5

I'm using CreateWindowEx to create an Edit control (a textbox), but saying CW_DEFAULT doesn't help with getting the default height of the textbox -- it just makes a window with a height of zero.

How do I get the system-default size of a textbox, so I can turn Edit control into a normal-looking textbox?

user541686
  • 205,094
  • 128
  • 528
  • 886
  • That is the documented behavior: ["if `CW_USEDEFAULT` is specified for a pop-up or child window, the *nWidth* and *nHeight* parameters are set to zero."](http://msdn.microsoft.com/en-us/library/ms632680.aspx). So `CW_USEDEFAULT` is definitely the wrong approach. – Ben Voigt Mar 05 '11 at 04:58

1 Answers1

11

The recommended size is 14 dialog units. Here is the reference

You can use MapDialogRect to convert dialog units into pixels.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Is there any way to get this programmatically? Or do I need to hard-code it into my program? – user541686 Mar 05 '11 at 05:40
  • 1
    You mean the 14 dialog units, or the number of pixels. Dialog units are defined in terms of the height of a line of text, so that number should be hard-coded. As I said, you then use `MapDialogRect` to convert to pixels, taking into account the user settings for font size and monitor DPI. – Ben Voigt Mar 05 '11 at 05:45