GetDialogBaseUnits is a crock

Raymond Chen

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.

0 comments

Discussion is closed.

Feedback usabilla icon