2c6b40b7e9be4a86abcb958c084b72cb91bd5383
3 Copyright (c) 2003 Microsoft Corporation
11 Include file for HIDPI / orientation / font change helper functions.
15 #ifndef __UIHELPER_H__
16 #define __UIHELPER_H__
20 #include "ms_ui_shguim.h"
26 ////////////////////////////////////////////////////////////////////////////////
27 // HIDPI functions and constants.
28 ////////////////////////////////////////////////////////////////////////////////
31 #define ILC_COLORMASK 0x00FE
35 // The two macros HIDPISIGN and HIDPIABS are there to ensure correct rounding
36 // for negative numbers passed into HIDPIMulDiv as x (we want -1.5 to round
37 // to -1, 2.5 to round to 2, etc). So we use the absolute value of x, and then
38 // multiply the result by the sign of x. Y and z should never be negative, as
39 // y is the dpi of the device (presumably 192 or 96), and z is always 96, as
40 // that is our original dpi we developed on.
43 #define HIDPISIGN(x) (((x)<0)?-1:1)
44 #define HIDPIABS(x) (((x)<0)?-(x):x)
45 #define HIDPIMulDiv(x,y,z) ((((HIDPIABS(x)*(y))+((z)>>1))/(z))*HIDPISIGN(x))
48 // Cached values of GetDeviceCaps(LOGPIXELSX/Y) for the screen DC.
50 EXTERN_C
int g_HIDPI_LogPixelsX
;
51 EXTERN_C
int g_HIDPI_LogPixelsY
;
54 // You need to define these somewhere in your .c files only if you make use of
55 // the scaling macros. (Defined in UIHelper.cpp).
57 #define HIDPI_ENABLE \
58 int g_HIDPI_LogPixelsX; \
59 int g_HIDPI_LogPixelsY;
64 #define SCALEX(argX) (HIDPIMulDiv(argX,g_HIDPI_LogPixelsX,96))
65 #define SCALEY(argY) (HIDPIMulDiv(argY,g_HIDPI_LogPixelsY,96))
67 #define UNSCALEX(argX) (HIDPIMulDiv(argX,96,g_HIDPI_LogPixelsX))
68 #define UNSCALEY(argY) (HIDPIMulDiv(argY,96,g_HIDPI_LogPixelsY))
70 #define SCALERECT(rc) { rc.left = SCALEX(rc.left); rc.right = SCALEX(rc.right); rc.top = SCALEY(rc.top); rc.bottom = SCALEY(rc.bottom);}
71 #define SCALEPT(pt) { pt.x = SCALEX(pt.x); pt.y = SCALEY(pt.y);}
73 //////////////////////////////////////////////////////////////////////////////
74 // FUNCTION: HIDPI_InitScaling
76 // PURPOSE: Initializes g_HIDPI_LogPixelsX and g_HIDPI_LogPixelsY. This
77 // should be called once at the beginning of any HIDPI-aware application.
79 __inline
void HIDPI_InitScaling()
83 if( g_HIDPI_LogPixelsX
)
87 g_HIDPI_LogPixelsX
= GetDeviceCaps(screen
, LOGPIXELSX
);
88 g_HIDPI_LogPixelsY
= GetDeviceCaps(screen
, LOGPIXELSY
);
89 ReleaseDC(NULL
, screen
);
92 //////////////////////////////////////////////////////////////////////////////
93 // FUNCTION: HIDPI_StretchBitmap
95 // PURPOSE: Stretches a bitmap containing a grid of images. There are
96 // cImagesX images per row and cImagesY rows per bitmap. Each image is
97 // scaled individually, so that there are no artifacts with non-integral
98 // scaling factors. If the bitmap contains only one image, set cImagesX
102 // HBITMAP* phbm: a pointer to the bitmap to be scaled.
103 // INT cxDstImg: the width of each image after scaling.
104 // INT cyDstImg: the height of each image after scaling.
105 // INT cImagesX: the number of images per row. This value should
106 // evenly divide the width of the bitmap.
107 // INT cImagesY: the number of rows in the bitmap. This value should
108 // evenly divide the height of the bitmap.
111 // Returns TRUE on success, FALSE on failure.
113 // If any scaling has occured, the bitmap pointed to by phbm is deleted
114 // and is replaced by a new bitmap handle.
116 BOOL
HIDPI_StretchBitmap(
124 //////////////////////////////////////////////////////////////////////////////
125 // FUNCTION: HIDPI_GetBitmapLogPixels
127 // PURPOSE: retrieves the DPI fields of the specified bitmap.
130 // HINSTANCE hinst: the HINSTANCE of the bitmap resource.
131 // LPCTSTR lpbmp: the ID of the bitmap resource. The MAKEINTRESOURCE
132 // macro can be used for integer IDs.
133 // INT* pnLogPixelsX: the returned value for the horizontal DPI field of
134 // the bitmap. This value is never less than 96.
135 // INT* pnLogPixelsY: the returned value for the vertical DPI field of
136 // the bitmap. This value is never less than 96.
139 // Returns TRUE on success, FALSE on failure.
141 BOOL
HIDPI_GetBitmapLogPixels(
148 //////////////////////////////////////////////////////////////////////////////
149 // FUNCTION: HIDPI_StretchIcon
151 // PURPOSE: stretches an icon to the specified size on 4.21 devices and later.
152 // On 4.20 and previous revisions of the OS, this is a no-op.
155 // HICON* phic: the icon to stretch.
156 // INT cxIcon: the desired width of the icon.
157 // INT cyIcon: the desired height of the icon.
160 // Returns TRUE on success, FALSE on failure.
162 // If any stretching occurred, the icon pointed to by phic is deleted and
163 // is replaced by a new icon handle.
165 BOOL
HIDPI_StretchIcon(
171 //////////////////////////////////////////////////////////////////////////////
172 // FUNCTION: HIDPI_ImageList_LoadImage
174 // PURPOSE: This function operates identically to ImageList_LoadImage, except
175 // that it first checks the DPI fields of the bitmap (using
176 // HIDPI_GetBitmapLogPixels); compares it to the DPI of the screen
177 // (using g_HIDPI_LogPixelsX and g_HIDPI_LogPixelsY), and performs scaling
178 // (using HIDPI_StretchBitmap) if the values are different.
181 // See the MSDN documentation for ImageList_LoadImage.
184 // See the MSDN documentation for ImageList_LoadImage.
186 HIMAGELIST
HIDPI_ImageList_LoadImage(
196 //////////////////////////////////////////////////////////////////////////////
197 // FUNCTION: HIDPI_ImageList_ReplaceIcon
199 // PURPOSE: Replaces an icon in an ImageList, scaling it from its original size
200 // to the size of the images in the ImageList.
203 // See the MSDN documentation for ImageList_ReplaceIcon.
206 // See the MSDN documentation for ImageList_ReplaceIcon.
208 int HIDPI_ImageList_ReplaceIcon(
214 //////////////////////////////////////////////////////////////////////////////
215 // FUNCTION: HIDPI_ImageList_AddIcon
217 // PURPOSE: Adds an icon to an ImageList, scaling it from its original size
218 // to the size of the images in the ImageList.
221 // See the MSDN documentation for ImageList_AddIcon.
224 // See the MSDN documentation for ImageList_AddIcon.
226 #define HIDPI_ImageList_AddIcon(himl, hicon) HIDPI_ImageList_ReplaceIcon(himl, -1, hicon)
228 //////////////////////////////////////////////////////////////////////////////
229 // FUNCTION: HIDPI_Rectangle
231 // PURPOSE: Draws a rectangle using the currently selected pen. Drawing occurs
232 // completely within the drawing rectangle (the rectangle has an "inside
233 // frame" drawing style).
236 // HDC hdc: the display context of the drawing surface.
237 // INT nLeft: left bound of rectangle
238 // INT nTop: top bound of rectangle
239 // INT nRight: right bound of rectangle plus one.
240 // INT nBottom: bottom bound of rectangle plus one.
243 // Returns TRUE on success, FALSE on failure.
245 BOOL
HIDPI_Rectangle(HDC hdc
, int nLeft
, int nTop
, int nRight
, int nBottom
);
247 //////////////////////////////////////////////////////////////////////////////
248 // FUNCTION: HIDPI_BorderRectangle
250 // PURPOSE: Draws a rectangle with the system border pen. Drawing occurs
251 // completely within the drawing rectangle (the rectangle has an "inside
252 // frame" drawing style).
255 // HDC hdc: the display context of the drawing surface.
256 // INT nLeft: left bound of rectangle
257 // INT nTop: top bound of rectangle
258 // INT nRight: right bound of rectangle plus one.
259 // INT nBottom: bottom bound of rectangle plus one.
262 // Returns TRUE on success, FALSE on failure.
264 BOOL
HIDPI_BorderRectangle(HDC hdc
, int nLeft
, int nTop
, int nRight
, int nBottom
);
266 //////////////////////////////////////////////////////////////////////////////
267 // FUNCTION: HIDPI_Polyline
269 // PURPOSE: Draws a polyline using the currently selected pen. In addition,
270 // this function provides control over how the line will be drawn.
273 // HDC hdc: the display context of the drawing surface.
274 // const POINT* lppt: array of POINTS that specify line to draw.
275 // INT cPoints: number of points in array.
276 // INT nStyle: the style the pen should be drawn in. This may be an
277 // existing pen style, such as PS_SOLID, or one of the following styles:
279 // PS_LEFTBIAS PS_UPBIAS PS_UPLEFT
280 // PS_RIGHTBIAS PS_DOWNBIAS PS_DOWNRIGHT
282 // These styles indicate how the pen should "hang" from each line
283 // segment. By default, the pen is centered along the line, but with
284 // these line styles the developer can draw lines above, below, to the
285 // left or to the right of the line segment.
288 // Returns TRUE on success, FALSE on failure.
291 #define PS_RIGHTBIAS 0x10
292 #define PS_LEFTBIAS 0x20
293 #define PS_DOWNBIAS 0x40
294 #define PS_UPBIAS 0x80
295 #define PS_DOWNRIGHT (PS_DOWNBIAS | PS_RIGHTBIAS)
296 #define PS_UPLEFT (PS_UPBIAS | PS_LEFTBIAS)
297 #define PS_BIAS_MASK (PS_RIGHTBIAS | PS_LEFTBIAS | PS_DOWNBIAS | PS_UPBIAS)
299 BOOL
HIDPI_Polyline(HDC hdc
, const POINT
*lppt
, int cPoints
, int nStyle
);
301 //////////////////////////////////////////////////////////////////////////////
302 // FUNCTION: HIDPI_BorderPolyline
304 // PURPOSE: Draws a polyline, but with the system border pen. In addition,
305 // this function provides control over how the line will be drawn.
308 // HDC hdc: the display context of the drawing surface.
309 // const POINT* lppt: array of POINTS that specify line to draw.
310 // INT cPoints: number of points in array.
311 // INT nStyle: the style the pen should be drawn in. See HIDPI_Polyline
315 // Returns TRUE on success, FALSE on failure.
317 BOOL
HIDPI_BorderPolyline(HDC hdc
, const POINT
*lppt
, int cPoints
, int nStyle
);
319 ////////////////////////////////////////////////////////////////////////////////
320 // Orientation functions.
321 ////////////////////////////////////////////////////////////////////////////////
323 //////////////////////////////////////////////////////////////////////////////
324 // FUNCTION: RelayoutDialog
326 // PURPOSE: Re-lays out a dialog based on a dialog template. This function
327 // iterates through all the child window controls and does a SetWindowPos
328 // for each. It also does a SetWindowText for each static text control
329 // and updates the selected bitmap or icon in a static image control.
330 // This assumes that the current dialog and the new template have all the
331 // same controls, with the same IDCs.
334 // HINSTANCE hInst: the hInstance of the current module.
335 // HWND hDlg: the dialog to layout.
336 // LPCWSTR iddTemplate: the new template for the dialog (can use
337 // the MAKEINTRESOURCE macro).
339 // ON EXIT: TRUE if success; FALSE if failure (either the iddTemplate is
340 // invalid, or there are two or more IDC_STATICs in the template).
342 BOOL
RelayoutDialog(HINSTANCE hInst
, HWND hDlg
, LPCWSTR iddTemplate
);
348 #endif // __UIHELPER_H__