Click to See Complete Forum and Search --> : Dialog boxes with default position (CW_USEDEFAULT)


wejrepus
January 19th, 2008, 09:40 PM
I'm trying to make my main window (a dialog) appear at the default position,
as if passing CW_USEDEFAULT,CW_USEDEFAULT to CreateWindowEx().
Setting the dialog's position to CW_USEDEFAULT had no effect. I
tried changing the dialog-template at runtime, but the problem is that DLGTEMPLATE's x & y fields are both shorts,
while CW_USEDEFAULT is defined as 0x80000000 - a DWORD. Setting x&y to -1 has no effect either.

So before i resort to hooking CreateWindow\Ex which CreateDialog internally uses,
is there any sane way to achieve this default positioning?

kirants
January 20th, 2008, 08:13 PM
What do you mean it has no effect ? Are you saying, the dialog box randomly appears at a different location each time ?

srelu
January 21st, 2008, 02:18 AM
Your dialog box has the WS_POPUP style.Pop-up windows must not be created with the CW_USEDEFAULT value for either the position or the size of the window. Pop-up windows that use CW_USEDEFAULT will exist but will have no size or no position or both.
Source: http://msdn2.microsoft.com/en-us/library/ms997562.aspx

wejrepus
January 21st, 2008, 08:27 PM
Your dialog box has the WS_POPUP style.Source: http://msdn2.microsoft.com/en-us/library/ms997562.aspx

It doesn't.

From .rc file:
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU


I even tried XORing the template's styles with WS_POPUP at runtime just to be sure,
but the dialog still appears at (0,0).

srelu
January 22nd, 2008, 01:55 AM
The system may assign some styles even if you don't declare them.

I suggest you to use GetWindowLong to retrieve the complete list of the styles your dialog has (the "WS_..." window styles are defined in winuser.h)

A dialog box, modal or modeless, normally has the WS_POPUP style ( see link: http://msdn2.microsoft.com/en-us/library/ms644994(VS.85).aspx )
The exception is the case when it's a child window. But CW_USEDEFAULT cannot be used with WS_CHILD either.