From: Woody on
For anyone interested, here is what I found. Modal dialog P creates
modal dialog F, which creates modeless A.

1) The coordinate difficulty came about because I was doing the
calculation in OnInitDialog (of F). At that time, F has not been
positioned relative to P, and its reported window rect is actually the
client rect of P.
2) When I move the calculation to OnCtlColor of F, MoveWindow on A
uses screen coords. I get the screen coords of the guide, so I can
position A correctly. I am never using client coords.
3) To get the screen coords of the client area, use GetWindowInfo.
This handy function returns both the window and client rectangles in
screen coords.
From: Joseph M. Newcomer on
It is incorrect to do this in OnCtlColor. The correct solution is to PostMessage a
user-defined message in OnInitDialog, and in handling that message, do the positioning.
Consider it an accident if it works in OnCtlColor, and functionality should not be
overloaded in this fashion.
joe

On Tue, 2 Feb 2010 11:58:49 -0800 (PST), Woody <ols6000(a)sbcglobal.net> wrote:

>For anyone interested, here is what I found. Modal dialog P creates
>modal dialog F, which creates modeless A.
>
>1) The coordinate difficulty came about because I was doing the
>calculation in OnInitDialog (of F). At that time, F has not been
>positioned relative to P, and its reported window rect is actually the
>client rect of P.
>2) When I move the calculation to OnCtlColor of F, MoveWindow on A
>uses screen coords. I get the screen coords of the guide, so I can
>position A correctly. I am never using client coords.
>3) To get the screen coords of the client area, use GetWindowInfo.
>This handy function returns both the window and client rectangles in
>screen coords.
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Woody on
On Feb 2, 7:54 pm, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
> It is incorrect to do this in OnCtlColor.  The correct solution is to PostMessage a
> user-defined message in OnInitDialog, and in handling that message, do the positioning.
> Consider it an accident if it works in OnCtlColor, and functionality should not be
> overloaded in this fashion.

I have a flag so it's only done once, so it's not an accident that it
works. At the time when the dialog is drawing its controls, it has
been moved to its final position by CDialog code.

You are right, though, that this is not an elegant soln. I looked for
a function that would be called once by the framework after the dialog
window had been positioned, but didn't find one; hence OnCtlColor.

Next time I'll try the message, although that's more work.
From: Joseph M. Newcomer on
No it is still an accident that it works. It relies on the fact that this method is
called. You should not overload functionality in this fasion. This is bad design.

Of course you did not find a function that was called when you wanted it, because it is so
trivial to implement yourself that there is no need to create a function as part of the
API set to do it. PostMessage of a user-defined message handles this nicely.
joe

On Wed, 3 Feb 2010 00:23:30 -0800 (PST), Woody <ols6000(a)sbcglobal.net> wrote:

>On Feb 2, 7:54�pm, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
>> It is incorrect to do this in OnCtlColor. �The correct solution is to PostMessage a
>> user-defined message in OnInitDialog, and in handling that message, do the positioning.
>> Consider it an accident if it works in OnCtlColor, and functionality should not be
>> overloaded in this fashion.
>
>I have a flag so it's only done once, so it's not an accident that it
>works. At the time when the dialog is drawing its controls, it has
>been moved to its final position by CDialog code.
>
>You are right, though, that this is not an elegant soln. I looked for
>a function that would be called once by the framework after the dialog
>window had been positioned, but didn't find one; hence OnCtlColor.
>
>Next time I'll try the message, although that's more work.
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm