February 17th, 2004

GetDialogBaseUnits is a crock

There are two functions that let you convert dialog units (DLUs) to pixels. One is GetDialogBaseUnits, which returns the base units directly (leaving you to do the math), and another is MapDialogRect, which takes a rectangle in DLUs and returns a rectangle in pixels.

What’s the difference?

As you can guess from the title of this entry, GetDialogBaseUnits is a crock. Since there is no HWND parameter to GetDialogBaseUnits, it doesn’t know which dialog box’s DLUs you want to retrieve. So it guesses.

And it always guesses wrong.

GetDialogBaseUnits returns the dialog base units for dialog boxes that use the default system font. But nobody uses the default system font any more. It screams “old and dorky”. But it remains the default for compatibility reasons. (And therefore so too does GetDialogBaseUnits.)

Everybody selects a custom font for their dialog box, usually “MS Sans Serif 8” or possibly “Tahoma” if they are one of those hip Windows 2000 folks.

That is why you must use MapDialogRect. The MapDialogRect function accepts a dialog box handle so it can use the correct font.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.