Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For my application I need to create a Dialog Box without using resource.
I am trying to do it with DialogBoxInderect function.
The code is unbelievably ugly but somehow I succeeded to do it.

The problem is that dialog, for some reason, is much bigger than I asked with much bigger fonts.

Here is how the dialog looks like if I load it from resource:
http://i28.fastpic.ru/big/2012/0209/a2/f24d30f05221dc7593ec1e039f8b8da2.png

And here is the dialog with the same size stated when I call DialogBoxInderect function.
http://i28.fastpic.ru/big/2012/0209/c4/5e133dd0cf19ea50fec21873aa0f49c4.png

Here is how it is defined in code:
C++
HGLOBAL             hGlobal;
LPDLGTEMPLATE       wlsDialogTemplate;
LPDLGITEMTEMPLATE   wlsDialogItemTemplate;
LPWORD              nextItem;
LPWSTR              itemString;
int32_t             itemStringLength;

// Check for memory allocation errors
hGlobal = GlobalAlloc(GMEM_ZEROINIT, 1024);
if (!hGlobal) 
    return -1;

wlsDialogTemplate = (LPDLGTEMPLATE)GlobalLock(hGlobal);

// Define a dialog box.
wlsDialogTemplate->style    = WS_CAPTION;
wlsDialogTemplate->x        = 0;
wlsDialogTemplate->y        = 0;
wlsDialogTemplate->cx       = 320;
wlsDialogTemplate->cy       = 115;

GlobalUnlock(hGlobal);
retCode = DialogBoxIndirect(0, (LPDLGTEMPLATE)hGlobal, 0, ActivateWlsMsgDialog);


And here is how it is defined in RC file:
C++
IDD_WLS_SMALL_MESSAGE_DLG DIALOGEX 0, 0, 320, 115
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "OK",ID_CUSTOM_OK,175,95,120,15
    PUSHBUTTON      "Cancel",ID_CUSTOM_CANCEL,45,95,120,15
    CTEXT           "Static",IDC_HEADER_TEXT,120,10,170,70
    CONTROL         "",IDC_LOGO,"Static",SS_BITMAP,16,10,83,70
END


As you can see, the second dialog is much bigger than defined. I tried to play with various style flags but without any success (That is why there is red cross on the bigger dialog).

Any help with that?
Thanks!
Posted
Updated 8-Feb-12 21:28pm
v3

Please try to set the same (or another special) font
at the WM_INITDIALOG part of ActivateWlsMsgDialog :)
 
Share this answer
 
Comments
Iron-Eagle 9-Feb-12 5:34am    
Thanks!
It really worked in init.
Espen Harlinn 9-Feb-12 9:18am    
5'ed!
Dialog sizes in RC files are given in dialog base units, not pixels so if you are setting them dynamically you need to convert from dialog units to pixels as described here[^].
 
Share this answer
 
Comments
Pablo Aliskevicius 9-Feb-12 5:25am    
Actually, the structure DLGTEMPLATE defines cx and cy in dialog units, so the pixel/dialog unit conversion is not the issue.
See:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645394(v=vs.85).aspx
Some manipulation of the window size in WM_INITDIALOG may help.
JM2B,
Iron-Eagle 9-Feb-12 5:32am    
I understand that the problem here is that the fonts that used are different, and what I need to change are fonts, not the sizes. I try to set flag DS_SETFONT and add the required header but it has very strange effect. ActivateWlsMsgDialog is being called constantly with WM_SETFONT flag, regardless what I return.

Any Ideas?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900