The information in this article applies to:
SUMMARYGetDialogBaseUnits() always assumes the system font when calculating dialog units. If you are using any font other than the system font, the return value may not be correct for your dialog box. This article offers two alternatives you can use to calculate dialog box units based on the current font. MORE INFORMATION
The horizontal base unit is equal to the average width (in pixels) of the
characters in the system font. The Help for GetDialogBaseUnits() suggests
the following code for calculating the correct units:
However, if you aren't using the system font, you need to do some additional calculations to get the right coordinates. Here are two methods: Method OneThe vertical dialog box unit is equivalent to the character height. The horizontal dialog box unit is equivalent to the average character width of the dialog box's font. The average character width is calculated by finding the average text extent of the alphabetic character set. This is necessary because tmAveCharWidth is not precise. Use this code:
Method TwoThe alternative is even easier. Using MapDialogRect() with a coordinate of x = 4, y = 8 will return the dialog box base units regardless of the dialog box's font. However, in most situations, the programmer doesn't need to know the dialog box base units. MapDialogRect() can be used directly to convert any dialog box units directly to device coordinates. The following sample code shows how it can be used to find the dialog box base units:
REFERENCES
For additional information, please see the following
article in the Microsoft Knowledge Base: Q125681 HOWTO: Calculate Dialog Base Units with Non-System-Based Font Additional query words: 2.50 2.51 2.52 3.00 3.10 3.20
Keywords : kbcode kbMFC KbUIDesign kbVC |
Last Reviewed: February 2, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |