The difference between Wm_initdialog and wm_create messages

Source: Internet
Author: User

http://blog.csdn.net/wangkehuai/article/details/7514277

Wm_create is a message that all windows can respond to, indicating that the window has been created (it is safe to use the window, such as drawing controls on it). In response to the WM_CREATE message response function, the dialog box and the child control has not been created, it is only the notification system said to start creating the window, the message after the response, the dialog box and child controls are only started to create. Therefore, the control cannot be modified and initialized in this message response function.

The WM_INITDIALOG message is a message that the dialog box can receive, indicating that the dialog box and all its child controls have been created. This state must be preceded by a call to the function that displays the dialog box, so you can add initialization and modification to the edit box control in the WM_INITDIALOG message response function.

==========================================

Do not be interrupted by MFC, MFC encapsulates too many things, in mind the API execution order on the line.

All windows are created after the registration window class is called CreateWindowEx, and after the successful creation (the HWND is valid but CreateWindowEx has not returned) the system automatically sends wm_create messages, so your oncreate will be executed, Here the window has been created successfully and you can safely create various child windows.

--------


The order in which messages are processed in the application (GO)

The order in which messages are processed in an MFC application

1.AfxWndProc () This function is responsible for receiving messages, finding the CWnd object to which the message belongs, and then calling Afxcallwndproc

2.AfxCallWndProc () This function is responsible for saving the message (the content is primarily the message identifier and message parameters) for later use by the application.
Then call the WindowProc () function

3.WindowProc () This function is responsible for sending the message to the Onwndmsg () function, and if it is not processed, call the DefWindowProc () function

4.ONWNDMSG ()         The function's functionality first sorts the messages in bytes, and for WM_COMMAND messages, calls the OnCommand () message
                     response function, for WM_NOTIFY messages
                     calls the OnNotify () message response function. Any missed messages will be a window message. Onwndmsg () function Search
                     the message image of the class to find a
                     can handle any window message processing function. If the onwndmsg () function cannot find such a handler function, then
                     returns the message to the WindowProc () function, which sends the message to the DefWindowProc () function

5.OnCommand () This function looks at whether this is a control notification (the LPARAM parameter is not NULL and if the lparam parameter is empty, the description
The message is not a control notification), and if it is, the OnCommand () function attempts to map the message to the control that manufactures the notification;
If he is not a control notification (or if the control rejects the mapped message) OnCommand () will call the OnCmdMsg () function

6.ONCMDMSG () Depending on the class that receives the message, the ONCMDMSG () function will potentially be in a process called command Routing
Pass command messages and control notifications.
For example, if the class that owns the window is a framework class, the command and notification messages are also passed to the view and document classes, and the
Class looks for a message handler function


Procedures for creating Windows for MFC applications

1.PreCreateWindow () This function is an overloaded function that can change the creation parameters in the overloaded function before the window is created
(You can set the window style, etc.)

2.PreSubclassWindow () This is also an overloaded function that allows you to first subclass a window

3.OnGetMinMaxInfo () This function is a message response function that responds to the WM_GETMINMAXINFO message, allowing the setting of the window's maximum or
Minimum size

4.OnNcCreate () The function is also a message response function that responds to the Wm_nccreate message and sends a message to tell the client area of the window
is about to be created

5.OnNcCalcSize () This function is also a message response function that responds to the wm_nccalcsize message, which is allowed to change the window client area size

6.OnCreate () The function is also a message response function that responds to the WM_CREATE message and sends a message telling a window has been created

7.OnSize () The function is also a message response function that responds to the WM_SIZE message and sends the message to tell the window that the size has been
Changed

The 8.OnMove () message response function, which responds to the Wm_move message, sends this message stating that the window is moving

9.OnChildNotify () The function is an overloaded function, called as part of a message map, telling the parent that the window is about to be told that a window has just been
Create


The order of the MFC application to close the window (non-modal window)

1.OnClose () message response function, Response window Wm_close message, send this message when the Close button is clicked

2.OnDestroy () message response function, Response window Wm_destroy message, when a window will be destroyed, send this message

3.OnNcDestroy () message response function, Response window Wm_ncdestroy message, when a window is destroyed after sending this message

4.PostNcDestroy () overloaded function, called by CWnd as the last action to handle the OnNcDestroy () function

The sequence of function calls in an MFC application that opens a modal dialog box

1.DoModal () overloaded function, overloaded DoModal () member function

2.PreSubclassWindow () overloaded function, which allows a window to be classified first

3.OnCreate () message response function, in response to a WM_CREATE message, sends this message to tell a window that it has been created

4.OnSize () message response function, in response to the WM_SIZE message, sends this message to tell the window that the size of the change

The 5.OnMove () message response function, which responds to the Wm_move message, sends this message to tell the window that it is moving

6.OnSetFont () message response function, which responds to the Wm_setfont message, sends this message to allow changes to the font of the control in the dialog box

The 7.OnInitDialog () message response function, which responds to the WM_INITDIALOG message, sends this message to allow initialization of the control in the dialog box.
or create a new control

The 8.OnShowWindow () message response function, which responds to the Wm_showwindow message, is called by the ShowWindow () function

9.OnCtlColor () message response function, Response Wm_ctlcolor message, sent by Parent window Changed dialog box or dialog box above control
The color

OnChildNotify () overloaded function, sent as a result of the WM_CTLCOLOR message


Order of closing modal dialogs in MFC applications

The 1.OnClose () message response function, which responds to the WM_CLOSE message, is called when the Close button is clicked.

2.OnKillFocus () message response function, Response Wm_killfocus message, when a window is about to lose keyboard input focus before being sent

3.OnDestroy () message response function, in response to a WM_DESTROY message, is sent when a window is about to be destroyed

4.OnNcDestroy () message response function, in response to a WM_NCDESTROY message, is sent when a window is destroyed

5.PostNcDestroy () overloaded function, called by CWnd as the last action to handle the OnNcDestroy () function

Order of open modeless dialog boxes

1.PreSubclassWindow () overloaded function that allows the user to first sub-categorize a window

2.OnCreate () message response function, in response to a WM_CREATE message, sends this message to tell a window that it has been created

3.OnSize () message response function, in response to the WM_SIZE message, sends this message to tell the window that the size of the change

4.OnMove () message response function, in response to a wm_move message, sends this message to tell the window that it is moving

5.OnSetFont () message response function, which responds to the Wm_setfont message, sends this message to allow changes to the font of the control in the dialog box


All of these executions are performed in a given order!

Only a clear understanding of the order in which the application is executed can be learned when writing code, when to do what, and where to deal with what!

The difference between Wm_initdialog and wm_create messages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.