Function: This function returns the basic unit of the system dialogue, which is the average width and height of the system font characters. For the dialog box that uses the system font, you can use these values to convert between the dialog box template, for example, between the dialog box template and pixel. For a dialog box that does not use the system font, the conversion from the unit of the dialog box template to the pixel depends on the font used in the dialog box. The MaPDialogRect function is used to easily convert one type of dialog box. MaPDialogRect considers the font and correctly converts the unit of a rectangle template to this pixel.
Function prototype: LONG GetDialogBaseUnits (VOID );
Parameter: none.
Return Value: the return value is a 32-bit value containing the basic unit of the conversation. The low-level characters returned contain the basic unit of the horizontal dialog box, and the high-level characters contain the basic unit of the vertical dialog box.
Note: The basic horizontal unit returned by the GetDialogBaseUnits function is the same as the average width of Characters in the system font in pixels. The basic vertical unit is the same as the average height of Characters in the system font in pixels; the basic unit of a dialog box that does not use the system font is equal to the average width and average height of the dialog box font characters in pixels. You can use the GetTextMetrics and GetTextExtentPoint32 functions to calculate these values for a selected font. However, if the calculation result is different from those executed by the system, you can use the MapDialogRect function to avoid possible errors. Each horizontal basic unit is the same as the four horizontal dialog box template units. Each Vertical Basic Unit is the same as the eight vertical dialog box template units. Therefore, use the following formula to convert the template unit of the dialog box to pixels:
PiselX = (temptateunitX★BaseunitX)/4; PiseIY = (templateunitY★BaseunitY)/8
Similarly, the following formula is used to convert pixels into dialog box template units: templateunitX = (pixelX★4)/baseunitX; templateunitY = (plxelY★8)/baseunitY
Windows CE: Windows CE does not support any extended error value of this function.
Quick query: Windows NT: 3.1 and later; Windows: 95 and later; Windows: 1.0 and later; header file: Winuser. h; library file: user32.lib
The above method is not successful at last, and then the ratio between them is calculated through fine-tuning:
VC6.0:
Control width/pixel width = 4/7
Control height/pixel height = 2/3
VS2005:
Control width/pixel width = 2/3
Control height/pixel height = 3/5