Classification of MFC messages in Visual C + + _c language

Source: Internet
Author: User
Standard (window) message: Window messages are generally related to the internal workings of a window, such as creating a window, drawing a window, destroying a window, usually from a system to a window, or from a window to a system. Send function SendMessage () or PostMessage (). In addition to WM_COMMAND, all messages that begin with WM_. Classes derived from CWnd can receive this type of message. Note: Standard messages do not require us to specify the processing function name, which is the default correspondence.

Macro name corresponds to Message message handler function
On_wm_char WM_CHAR OnChar
On_wm_close Wm_close OnClose
On_wm_create wm_create OnCreate
On_wm_destroy Wm_destroy OnDestroy
On_wm_lbuttondo Wnwm_lbuttondown OnLButtonDown
On_wm_lbuttonup Wm_lbuttonup OnLButtonUp
On_wm_mousemove Wm_mousemove OnMouseMove
On_wm_paintwm_paint OnPaint

Command messages: command messages are usually related to processing a user request, and the command message is generated when the user clicks a menu or toolbar. Messages that are sent to a class or function that can handle the message, such as loading text, saving options, and so on, are rendered in wm_command. In MFC, a menu identifier (ID) is used to distinguish between different command messages, and in the SDK, the wparam parameters of the message are identified. Classes derived from CCmdTarget can receive such messages, and their wparam record which menu item the message comes from.

On_command (Idm_about, Onabout)
On_command (Idm_filenew, OnFileNew)
On_command (Idm_fileopen, OnFileOpen)
On_command (Idm_filesave, OnFileSave)

Control message: A message generated by a control, such as a button's click, the selection of a list box, and so on, to notify the occurrence of an event to its parent window (usually a dialog box). Such messages are also rendered in wm_command form. Classes derived from CCmdTarget can receive such messages.

Control macro Message Handler function
Button on_bn_clicked (<id>,<memberFxn>) memberfxn
ComboBox on_cbn_dblclk (<id>,<memberFxn>) memberfxn
Edit On_en_setfocus (<id>,<memberFxn>) memberfxn
ListBox on_lbn_dblclk (<id>,<memberFxn>) memberfxn

CWnd is a derived class of CCmdTarget, and Cmenuapp and Cmenudoc in a single document program in MFC are derived classes that belong to CCmdTarget and do not contain CWnd classes.

Routing of MFC Command messages: AfxWndProc (replacing the window procedure function)->afxcallwndproc->windowproc->onwnddmsg-> (call OnCommand if it is a command message; Call OnNotify If it is a notification message->oncmdmsg
Distinction between standard and non-standard messages: Standard message: With control followed by operations; non-standard message: Just a simple hint.

You can design a message image form in many categories of the program (each category can have only one message image form, but it may not), and receive and process messages. Any Windows messages can be stopped as long as they are CWnd derived classes. MFC classes that are not window-independent, such as CDocument and CWinApp, must be derived from CCmdTarget if you also want to process messages, and you may only receive WM_COMMAND command 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.