Classification of MFC messages in Visual C ++

Source: Internet
Author: User
Tags cve

Standard (window) messages: Window messages are generally related to the internal operation of the window, such as creating a window, drawing a window, and destroying a window. Generally, messages are sent from the system to the window or from the window to the system. Send the SendMessage () or PostMessage () function (). All messages starting with WM _ Except WM_COMMAND. Classes derived from CWnd can receive such messages. Note: For standard messages, you do not need to specify the handler name, which is the default correspondence.

Message Processing function corresponding to macro name
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 message: a command message is usually related to processing user requests. When a user clicks a menu or toolbar, the command message is generated. Messages such as classes or functions (such as loading text and saving options) that can process the message are displayed as WM_COMMAND. In MFC, different command messages are distinguished by menu IDs. In SDK, messages are identified by wParam parameters. Classes derived from cve-target can receive such messages. Its wParam records the menu item from which 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: messages generated by the control, such as clicking a button or selecting a list box, are generated to notify the parent window (usually a dialog box) of events. Such messages are also presented in the form of WM_COMMAND. Classes derived from csf-target can receive such messages.

Control macro Message Processing 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 the derived class of cve-target. In the single-document program of MFC, both CMenuApp and CMenuDoc belong to the derived class of cve-target and do not include the CWnd class.

MFC command message routing: AfxWndProc (with the window function replaced)-> AfxCallWndProc-> WindowProc-> OnWnddMsg-> (if the command message is used, Oncommand is called; call OnNotify if the message is advertised)-> OnCmdMsg
Standard Messages and non-standard messages are differentiated: Standard Messages: followed by control; non-standard messages: Just a simple prompt.

You can design a "message image table" (each category can have only one message image table, but it does not) in many categories of the program to receive and process messages. As long as it is a CWnd derivative type, you can block any Windows message. If you want to process messages in a Windows-independent MFC category (such as CDocument and CWinApp), you must derive the message from c1_target and only receive the WM_COMMAND message.

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.