Q145994: HOWTO: Calculate Dialog Units When Not Using the System Font | KnowledgeBase Archive
Posted by jpluimers on 2025/07/17
It is odd that Microsoft now verifies to an external party because most of the Microsoft KB articles got deleted: [Wayback/Archive] Q145994: HOWTO: Calculate Dialog Units When Not Using the System Font | KnowledgeBase Archive.
Part of them document aspects from Microsoft Foundation Class Library – Wikipedia which is still supported.
Via: [Wayback/Archive] How does the dialog manager calculate the average width of a character? – The Old New Thing:
Some time ago, I explained that the
MapDialogRectfunction requires the handle to a dialog box because the mapping from dialog units to pixels is dependent upon the default font of the dialog box, so you need to know which dialog box you are converting.I noted that if you don’t have a dialog box, and you don’t want to find or make one, then you can simulate the calculations yourself using the standard formulas:
8 vertical dlu =1 character tall4 horizontal dlu =1 average character wideAccording to Knowledge Base article Q145994, the calculation of the character height and width are performed as follows:
For height, call
GetTextMetricsand use thetmHeight.For average width, get the text extent of the string
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzand divide it by 52, rounding to the nearest integer. Do not use the
tmAveCharWidthfrom the text metrics. Despite its name, it is not the average of anything. It’s just the width of the character x.Bonus chatter: Maybe the font people interpreted it to mean “the width of an average character”, rather than “the average width of a character.”
Related:
- [Wayback/Archive] Why isn’t MapDialogRect mapping dialog rectangles? – The Old New Thing
- [Wayback/Archive] GetDialogBaseUnits is a crock – The Old New Thing
–jeroen






Leave a comment