Discussion:
How to move a modal dialog
(too old to reply)
RAN
2007-08-23 21:11:24 UTC
Permalink
Hi,

How do i show my modal login CDialog on the right bottom of the
screen ?
If i do DoModal() its in the center of the screen.
David Wilkinson
2007-08-23 21:22:04 UTC
Permalink
Post by RAN
Hi,
How do i show my modal login CDialog on the right bottom of the
screen ?
If i do DoModal() its in the center of the screen.
RAN:

You can move it in OnInitDialog().

David Wilkinson
Visual C++ MVP
AliR (VC++ MVP)
2007-08-23 21:19:30 UTC
Permalink
In the OnInitDialog method of the dialog use SetWindowPos to move it.

AliR.
Post by RAN
Hi,
How do i show my modal login CDialog on the right bottom of the
screen ?
If i do DoModal() its in the center of the screen.
Joseph M. Newcomer
2007-08-24 01:14:45 UTC
Permalink
Actually, this doesn't work. After it returns from OnInitDialog, the dialog is forced to
center-screen. The trick is to PostMessage a user-defined message, and in its handler, do
the SetWindowPos.

You might consider being multi-monitor aware as well. You need to get the rectangle of
the screen of the active monitor, then do a GetWindowRect() of your dialog.

CRect monitor;
...get monitor coordinates
CRect w;
GetWindowRect(&w);
SetWindowPos(NULL, monitor.right - w.Width(), monitor.bottom - w.Height(), 0, 0,
SWP_NOSIZE | SWP_NOZORDER);

for a single monitor system, you can use ::GetSystemMetrics, e.g.,

CRect monitor(0, 0, ::GetSystemMetrics(SM_CXSCREEN), ::GetSystemMetrics(SM_CYSCREEN));

joe
Post by AliR (VC++ MVP)
In the OnInitDialog method of the dialog use SetWindowPos to move it.
AliR.
Post by RAN
Hi,
How do i show my modal login CDialog on the right bottom of the
screen ?
If i do DoModal() its in the center of the screen.
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
David Wilkinson
2007-08-24 13:34:25 UTC
Permalink
Post by Joseph M. Newcomer
Actually, this doesn't work. After it returns from OnInitDialog, the dialog is forced to
center-screen. The trick is to PostMessage a user-defined message, and in its handler, do
the SetWindowPos.
Joe:

I don't think so. I move dialogs in OnInitDialog() all the time.

David Wilkinson
Visual C++ MVP
AliR (VC++ MVP)
2007-08-24 14:28:38 UTC
Permalink
Joe is partially correct, if you move the window to 0,0 then when
OnInitDialog returns it will be centered again. Any other coordinate it
would be ok.

AliR.
Post by David Wilkinson
Post by Joseph M. Newcomer
Actually, this doesn't work. After it returns from OnInitDialog, the dialog is forced to
center-screen. The trick is to PostMessage a user-defined message, and
in its handler, do
the SetWindowPos.
I don't think so. I move dialogs in OnInitDialog() all the time.
David Wilkinson
Visual C++ MVP
Tom Serface
2007-08-24 16:20:19 UTC
Permalink
Thanks Ali, that is interesting information. I've never moved a dialog to
0,0 so I was seeing what David was seeing (that it seems to work). I've
also expanded dialogs to fill the whole screen in OnInitDialog() and that
seems to work as well.

Tom
Post by AliR (VC++ MVP)
Joe is partially correct, if you move the window to 0,0 then when
OnInitDialog returns it will be centered again. Any other coordinate it
would be ok.
AliR.
Post by David Wilkinson
Post by Joseph M. Newcomer
Actually, this doesn't work. After it returns from OnInitDialog, the
dialog is forced to
center-screen. The trick is to PostMessage a user-defined message, and
in its handler, do
the SetWindowPos.
I don't think so. I move dialogs in OnInitDialog() all the time.
David Wilkinson
Visual C++ MVP
Joseph M. Newcomer
2007-08-25 22:01:55 UTC
Permalink
In fact, that's what I was trying to do: pin it to the top left corner!
joe
Post by AliR (VC++ MVP)
Joe is partially correct, if you move the window to 0,0 then when
OnInitDialog returns it will be centered again. Any other coordinate it
would be ok.
AliR.
Post by David Wilkinson
Post by Joseph M. Newcomer
Actually, this doesn't work. After it returns from OnInitDialog, the
dialog is forced to
center-screen. The trick is to PostMessage a user-defined message, and
in its handler, do
the SetWindowPos.
I don't think so. I move dialogs in OnInitDialog() all the time.
David Wilkinson
Visual C++ MVP
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Nobody
2007-08-23 21:24:41 UTC
Permalink
Hi,

SetWindowPos()
http://msdn2.microsoft.com/en-us/library/5bc5w1zz(VS.80).aspx

Or

MoveWindow()
http://msdn2.microsoft.com/en-us/library/ms633545.aspx


HTH,
Post by RAN
Hi,
How do i show my modal login CDialog on the right bottom of the
screen ?
If i do DoModal() its in the center of the screen.
Tom Serface
2007-08-23 21:27:20 UTC
Permalink
You may also be interested in this library. It can remember the size and
possible the user used previously and restore it the next time the dialog is
opened:

http://www.codeproject.com/dialog/resizabledialog.asp

Tom
Post by RAN
Hi,
How do i show my modal login CDialog on the right bottom of the
screen ?
If i do DoModal() its in the center of the screen.
Continue reading on narkive:
Loading...