The process of creating Windows for an MFC application good

Source: Internet
Author: User

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 () The function is responsible for saving the message (the content of the message is primarily the information identifier and message parameters) for later use by the application, and then calling 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 function first sorts the message by byte, and for the WM_COMMAND message, calls the OnCommand () message response function, and calls the OnNotify () message response function for the WM_NOTIFY message. Any missed messages will be a window message. The onwndmsg () function searches the message image of the class to find a handler function that can handle any window message. If the onwndmsg () function cannot find such a handler function, it 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, if the lparam parameter is empty, 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 () calls the OnCmdMsg () function

6.ONCMDMSG () Depending on the class that receives the message, the ONCMDMSG () function will potentially pass command messages and control notifications during a process called command Routing. 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 a message handler function is found for the class

Procedures for creating Windows for MFC applications

1.PreCreateWindow () This function is an overloaded function, you 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, in response to a WM_GETMINMAXINFO message, allowing the setting of the maximum or minimum size of the window

4.OnNcCreate () The function is also a message response function that responds to the Wm_nccreate message, sending a message to tell the window that the client area 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 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 created

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

7.OnInitDialog () message response function, which responds to the WM_INITDIALOG message, sends this message to allow the control to initialize the dialog box, or to 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, is sent by the parent window the color of the control above the dialog box or dialog box

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!

http://blog.csdn.net/qing666888/article/details/50552694

The process of creating Windows for an MFC application good

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.