Solved

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

Posted on 1998-03-20
11
256 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 50 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now