3

I am trying to get a Win32 dialog that is 500x520 px, but in my .rc file, these settings get me a bigger window than I expected.

IDD_DIALOG1 DIALOG DISCARDABLE  0, 0, 500, 520
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX

Is there a scaling factor somewhere?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
olilarkin
  • 460
  • 6
  • 17

1 Answers1

6

The units in a dialog resource are dialog units which are normalized by the dimensions of the dialog font by a rather convoluted process. You can convert from dialog units to screen pixels with MapDialogRect().

There are lots more details in the documentation for GetDialogBaseUnits() but the recommended approach is to call MapDialogRect() and let it do the hard work for you.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Yeah, the *reason* you shouldn't use `GetDialogBaseUnits` is because its calculations are based on the default system font, which [no one uses anymore](http://blogs.msdn.com/b/michkap/archive/2008/08/14/8867856.aspx). Unfortunately, if the window in question is not a dialog, you don't have much choice, as `MapDialogRect` doesn't work. – Cody Gray - on strike May 14 '11 at 11:00
  • @CodyGray The documentation for GetDialogBaseUnits explains how the units work. It also tells you which function to call to get the measurements for a non-system font, which you also can use for a non-dialog window. – user253751 Aug 31 '21 at 15:48