Solved

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

Posted on 1998-03-20
11
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 140
I could not build boost code, 10 107
draw a Christmas tree by using a nested loop? 26 92
Autosar OS Multicore Share Resources confusion ? 2 112
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.

697 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