Further, dialog box measurements are given in dialog base units. One horizontal base unit is equal to one-fourth of the average character width for the system font. One vertical base unit is equal to one-eighth of the average character height for the system font. An application can retrieve the number of pixels per base unit for the current display by using the GetDialogBaseUnits function. The low-order word of the return value, from the GetDialogBaseUnits function, contains the horizontal base units and the high-order word of the return value, from the GetDialogBaseUnits function, contains the vertical base units.
Using this information, you can compute the dialog base units for a dialog box using font other than system font:
As the font of a dialog box changes, the actual size and position of a control also changes.
horz pixels == 2 * horz dialog units * (average char width of dialog font
/ average char width of system font)
vert pixels == 2 * vert dialog units * (average char height of dialog font
/ average char height of system font)
One dialog box base unit is equivalent to the number of pixels per dialog box unit as follows:
Average character width and height of a font can be computed as follows:
1 horz dialog base unit == (2 * average char width dialog font /
average char width system font) pixels
1 vert dialog base unit == (2 * average char height dialog font /
average char height system font) pixels
hFontOld = SelectObject(hdc,hFont);
avgWidth = (size.cx/26+1)/2;
avgHeight = (WORD)tm.tmHeight;
You can use the MapDialogRect function to convert dialog box units into pixels, but there is no function that will convert pixels into dialog box units. You can use the formulas shown here to perform this conversion.
رقم الموضوع: 125681 - آخر مراجعة: 11/07/2005 - المراجعة: 1