?
Solved

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

Posted on 1998-03-20
11
Medium Priority
?
276 Views
Last Modified: 2010-04-10
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
0
Comment
Question by:youcef
  • 7
  • 3
11 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 150 total points
ID: 1183660
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183661
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).  
0
 
LVL 11

Expert Comment

by:alexo
ID: 1183662
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.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 22

Expert Comment

by:nietod
ID: 1183663
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.
0
 

Author Comment

by:youcef
ID: 1183664
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            
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183665
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?
0
 

Author Comment

by:youcef
ID: 1183666
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

0
 
LVL 22

Expert Comment

by:nietod
ID: 1183667
Is this a modal or modeless dialog?
How are the controls being added to the dialog window?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183668
If you have a small section of code to post to that may help to.
0
 

Author Comment

by:youcef
ID: 1183669
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
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183670
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.  

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question