Re: Child Window Creation

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I'll remember that next time! :-)

-- David


"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message news:6pl305pshvvcqjt3a90n911a3caouur9t7@xxxxxxxxxx
Actually, all you had to do was call UpdateWindow as the first thing in your handler!
joe

On Wed, 6 May 2009 08:04:51 -0700, "David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote:

For the record, I also have experienced that a newly created window is not
painted until all posted messages have been pumped. This caused me grief
when I wanted the window to paint prior to commencing a 2 second
initialization. I tried starting the initialization code by posting a UWM_
message in OnCreate(), but it was getting handled before the window painted.
The only way I found to paint first was to set a 0 ms timer and to handle
the initialization in OnTimer(). Timer messages are apparently delayed
until after painting.

-- David


"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:404105pi5ncttp6qjd52i7bqjob8ukg25j@xxxxxxxxxx
I did not say your version was running differently. I did observe that in
general a
WM_PAINT is not sent unless the message queue is empty, so a PostMessage
is supposed to
preempt this behavior.
joe

On Tue, 5 May 2009 11:39:34 -0500, "AliR \(VC++ MVP\)"
<AliR@xxxxxxxxxxxxx> wrote:

Well, I don't know what to tell you Joe, but I tested this and when
DDX_Control is used the WM_PAINT got called before the PostMessage was
processed, and there is not a single UpdateWindow or Invalidate, or
WM_PAINT
message sending in my sample code.

I guess I should call Microsoft and complain that my OS is running
differently than yours.

AliR.


"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:v0p005pl0g5uv9vqad4c7n2pn85bpbdm48@xxxxxxxxxx
Unless there is an explicit UpdateWindow, a WM_PAINT will be preempted
by
PostMessage.
joe

On Tue, 5 May 2009 10:21:16 -0500, "AliR \(VC++ MVP\)"
<AliR@xxxxxxxxxxxxx> wrote:

That's not entirely true. When the control is attached to the object
using
DDX_Control, and you post a message from within PreSubclassWindow, there
are
a host of other messages that can be sent to the window before your
posted
message gets processed, for example WM_PAINT is one that will almost
always
gets processed before the user posted message.

AliR.


"Malachy Moses" <malachy.moses@xxxxxxxxx> wrote in message
news:26065732-0e45-454c-9af2-025ff34fadc3@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On May 4, 2:19 pm, "AliR \(VC++ MVP\)" <A...@xxxxxxxxxxxxx> wrote:
Hi Everyone,

First of all don't laugh, at least try not to.

I have a CWnd derived class, which gets created using Create method
and
in
some places gets subclassed using DDX_Control.

Now this CWnd derived class needs to create some child controls of its
own.

Where would you create these child controls?

If I do it in PreSubclassWindow, it will only work correctly when the
control is subclassed using DDX_Control, and will break when it is
created
with Create, since the window is not created yet, and there is no
HWND.

If I do it in OnCreate, then it will work for windows that are
dynamically
created using Create, but not for subclassed ones, since it will never
get
called.

Thanks
AliR.
P.S. this question should get my MVP revoked.

In similar situations, from inside PreSubclassWindow, I have
PostMessage'd a custom message to myself (like
UWM_DOPOSTCREATIONINIT). The message seems to be inserted right
behind the WM_CREATE message, and gets handled right after it.

As you know, PreSubclassWindow is called from both the DDX-dialog
route and the Create(Ex) route, so you need the PostMessage only from
inside PreSubclassWindow, and you don't need a bunch of flags to keep
track of what gets done when.

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

.



Relevant Pages

  • Re: Child Window Creation
    ... painted until all posted messages have been pumped. ... but it was getting handled before the window painted. ... DDX_Control, and you post a message from within PreSubclassWindow, there ...
    (microsoft.public.vc.mfc)
  • Re: Removing the Maximize Menu From System Menu
    ... in the WM_SYSMENU handler). ... I have window which has the minimize, and system icon style. ...
    (microsoft.public.vc.mfc)
  • Re: Fullscreen PPC
    ... timer handler and nothing in the WM_ACTIVATE handler, ... You select the window that you want to know about from the Windows List ... Paul T. ... // Resize the window over the taskbar area. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Thread and Timer
    ... class CMyThread: public CWinThread ... CAsyncSocket creates a dummy window to handle callback notifications, ...
    (microsoft.public.vc.mfc)
  • Re: Dialog ghost left on window
    ... In my dialog's OnClosed handler, ... // This should invalidate the ApplicationForm... ... > a user mode long processing loop, ... >> I have a Systems.Windows.Forms.Form-based window. ...
    (microsoft.public.dotnet.framework.windowsforms)