简体   繁体   中英

order of events when a window starts in Visual C++ MFC

suppose that I have a class derived from CWnd that have the event handler functions OnPaint , OnCreate and OnSize . As you know all of them are occured when the window starts but I want to see what is the order between them.
when I set a breakpoint in one of them, after ending the function, the control is not passed to another and goes to one of the MFC's built-in .cpp files for example wincore.cpp ?
How can I understand the order? any links or teach me a way to prevent the control from going to MFC built-in classes?

The order in which messages arrive is not fully defined and documented. However, some messages are ordered with respect to others. The MSDN explicitly states that WM_NCCREATE is sent prior to WM_CREATE . The documentation for WM_CREATE has a few more hints as far as the order is concerned (emphasis mine):

Sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. (The message is sent before the function returns .) The window procedure of the new window receives this message after the window is created, but before the window becomes visible .

It should be immediately clear, that a window has to exist to receive additional messages. Consequently, the first WM_SIZE will be sent after WM_CREATE . As for WM_PAINT it requires that a window is visible. Plus, it is a low priority message that is only generated if the message queue is empty.

During window creation the order is WM_CREATE , WM_SIZE , WM_PAINT .

If you are only interested in observing messages you can use a tool like Spy++ (spyxx.exe) that comes with Visual Studio. It can log arbitrary messages and gives you detailed information. If this is for educational purposes (as opposed to deducing behavior) it is a very helpful tool.

Note to downvoters: If you feel this answer is inaccurate or needs improvement please leave a note to help future visitors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM