Re: Positioning a child dialog centrally in teh parent
I believe that is done in _AfxPostInitDialog for dialogs. It doesn't hurt
to call CenterWindow() in OnInitDialog(). Of course the user can move the
child dialog any time they want, but a looks like a simple, subsequent, call
to CenterWindow() puts it back based on the parent unless the user does
something like CenterWindow(GetDesktopWindow()) to override teh default
functionality.
If a popup window is created without a parent I think it is centered on the
screen. This is a lot less work than I thought. I tend to leave windows
where the user puts them (even when they rerun the program) unless they are
temp windows like message boxes, so I haven't seen this in some time.
Tom
"David Ching" <dc@remove-this.dcsoft.com> wrote in message
news:uZ$PeCnUKHA.5208@TK2MSFTNGP05.phx.gbl...
"Tony" <tony@home.com> wrote in message
news:uiF8KXlUKHA.3720@TK2MSFTNGP02.phx.gbl...
Hi,
I am sure I have seen this question asked before, but I cant seem to find
a solution to my problem.
I want to programmatically centre my child dialog in the centre of the
parent window, and cant seem to find a sample to explain how to do this.
I have tried SetWindowPos in the OnInitDialog, but the default X pos and
Y pos coordinates seem to override the CRect left and top positions I
have calculated.
Can someone help me to position the child please.
I'm running Visual C++ .Net
Doesn't CDialog::DoModal() do this automatically? I seem to recall it
sets a window hook and then centers the window after it is created.
Anyway, my modal dialogs seem to be always be centered without my doing
anything special.
-- David