Link to home
Start Free TrialLog in
Avatar of youcef
youcef

asked on

What messages are sent when a Window (dialog) is created

Can anyone shed a light on :
1- what messages are sent?
2- in which order?
3- what each message does?
4- and if the message is sent directly to a window procedure or posted in the queue?

When a dialog or a window is created.

Thanks a lot
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

The messages change depending on the window's style and propertied and acctions taken by its window procedure.  There are two messages that will always be sent and are typically used to "hook" into the creation process, if that is what you want.

The WM_NCCREATE message will be sent first.  I beleive this is garanteed, at least I have never seen a case where a message was sent before it.  This is a good message to hook for initilaizations that must take place immediately.  You must pass the message on to the default window procedure.  The window procedure will use this message to perform its initializations.  The default window procedure will uses this message to send other messages, for example it may send the WM_GETMINMAXINFO for a resizable window.

The WM_CREATE message may come next or soon after.  (Depending in what the default window procedure does with the NCCREATE message.)   This is the message that most window procedures will hook for perform initializations.

If you give me an idea of why you wnat this information, I may be able to give you more  information.  The other option is that you can test this stuff yourself using the Spy tool (from the windows SDK, or VC++, Borland C++ has something similar too).  
If it's a dialog, a WM_INITDIALOG message will be sent too.
I beleive that all messages involved in the creation of the window are sent (not posted).  In general, only "asynchronous" messages are posted.  E.g., messages dealing with user input (mouse movement, clicks, keyboard), DDE, timers, control notification messages, and, of course, WM_COMMAND, WM_PAINT and WM_QUIT.

Yes, these messages are definitly sent.  The CreateWindow() procedure sends the messages and will not return until the window procedure for the new window has handled them.  Thus the code that calls CreateWindow() can assume these messages have been sent and handled.
Avatar of youcef

ASKER

Hi nietod, I really liked your answer you've touched the meat of the question BUT it seems that you stopped carry on explaining the sequence of the messages...
I know there are quiet a few of them but they are numbered and can be covered, so if you dont mind (sorry of taking your time) can you explore them. like:
CreateWindow sends

1-      WM_NCCREATE sends
            WM_GETMAXMININFO directly
            WM_BLABLA sends
                  WM_XXX post WM_AAA in the queue
                  WM_YYY


2-       WM_CREATE
....

Thanks a lot            
You didn't quite understand.  I beleive there are only two you can count on in every case that is WM_NCCREATE and WM_CREATE.  The others will depend on (1) the window's properties (its styles, whethor or not it is visible, etc) (2) the actions taken by the window procedure in response to these message.  

Typically you will get relatively few messages, maybe 5 or 6 before CreateWindow() returns.  But it will depend.  One you might always get (I don't know for sure) is WM_NCCALCSIZE.  I know that it sometimes occurs.  I can't say it always occurs.  

If you want to know what messages are occuring for a particular window (particular style, particular parent, particular window procedure, etc)  use the Spy utilites.  

Or approach it from the other side, what is it you want to do?
Avatar of youcef

ASKER

Thanks guys for your time and trying to answer my questions, I really appreciate it.
Well, My problem is as follow:
- I am subclassing a static control in order to create my own control which consist of viewing video images captured by a video camera (QuickCam). This control should be used in a dialog like any other control. The problem I am having are:
*  I find it difficult to know when my control is created so that I can use his handle to pass as a parameter to the video creation function.
* I want this creation and video viewing to be automatic when my control is in the dialog. i.e  If I am use in a dialog i.e when the dialog is created and all the controls on it are created and displayed my video start playing.

I am using VC++ and MFC.

Thanks for any help

Is this a modal or modeless dialog?
How are the controls being added to the dialog window?
If you have a small section of code to post to that may help to.
Avatar of youcef

ASKER

1- It's Modal Dialog.
2- I am using App Studio (VC++) to create the control and put them in the dialog, and after App studio and Class wizard created all the necessary code, I've just replace CStatic with CMyStatic;

If you want more infos please let me know

Thanks
I don't use MFC so there may be a more MFC approach than this.  For a model dialog you can hook the WM_INITDIALOG message in the dialog window procedure.  When it is called the dialog has been created and its children have been created, but the dialog has not been displayed.  (It is just about to be displayed)    This would be a good place to "start the video", that is to get it running.  It may be a good place to do all of your initialization, it might not.  Another good place to do iniitialization is in the WM_CREATE message.  For example, you might want to initalize the video control on its WM_CREATE message (but you probably don't want to start it running at that time).

If you don't want to start the video running until the dialog is displayed, you could hook the WM_PAINT message for some window (pobably the control that displays the video).  Start the video running the first time the WM_PAINT is received.