Some common knowledge points of MFC

Source: Internet
Author: User
Tags function prototype

1.difference between DDX_Control and DDX_Text

DDX_Text () can be understood as the string variables and the text of the control ( windowtext ) to correlate
The role of DDX_Control () can be understood as associating the variable with the control itself .
Dodataexchange(PDX)
is the function that handles all variables that exchange data with their associated controls.

void CView::D odataexchange (cdataexchange* PDX)

CFormView::D odataexchange (PDX);
DDX_Text (PDX, Idc_id_value, M_strid);
DDX_Control (PDX, Idc_id_value, M_editid);

In the program
by update (TRUE), the value on the control is obtained to M_strid, and when the modification is processed, it is returned to the control via update (FALSE), and the interface displays
Via M_editid.getwindtext (str), the value is obtained, processed, and returned via M_editid.setwindtext (str) to the Control interface display

2.MFC Begin_message_map ()

Begin_message_map (Cpassapp, CWinApp)    on_command (Id_help, CWinApp::OnHelp) End_message_map ()

These are macro definitions, not functions.
Add your message response function between Begin_message_map () and End_message_map (), adding a portal to each message handler function

Begin_message_map (Theclass, BaseClass)

Parameters:

Theclass Specifies the name of the class to which the message map belongs.
BaseClass Specifies the name of the base class for the Theclass.


Description
Use the BEGIN_MESSAGE_MAP macro to start the definition of your message map.
In the implementation file of the member function of your class (. CPP), start the message map with the BEGIN_MESSAGE_MAP macro, then add a portal for each message handler and end the message map with the END_MESSAGE_MAP macro.

The format for each message-map entry is as follows:
On_notification (ID, MEMBERFXN)
Where ID specifies the ID of the child window of the control that sent the notification, and MEMBERFXN specifies the name of the member function in the parent object that handles the notification.
The function prototype format of the parent object is as follows:
afx_msg void Memberfxn ();

The possible message map portals are as follows:

Map Portal When to send a message to a parent object
On_bn_clicked When the user clicks the button
On_bn_doubleclicked When the user double-clicks the button

The difference between 3.on_command and on_message

There are three types of messages that are transmitted in an MFC application: Window messages, command messages, and control notifications. window messages are generally related to the internal workings of the window, such as creating Windows, drawing windows, destroying windows, and so on. Typically, messages are sent from the system to a window, or from a window to a window. For a complete list of window messages, refer to the MFC documentation. Command message command messages are generally related to handling user requests, and when a user clicks a menu item or toolbar, the command message is generated and sent to the class object that can handle the request (for example, Mount file, edit text, save options, and so on). Control notifications Typically, control notifications are sent by a control window to a parent window, such as opening a combo box, when certain important events occur. Control notifications provide an opportunity for the parent window to further control child windows.      For example, when you open a combo box, the parent window can populate it with a message that was not available when the combo box was first built. Both On_command and on_message are adding message handlers to the message routing table, but the ON_COMMAND corresponding message ID is always WM_COMMAND, and On_message's message ID is On_ The first parameter of COMMAND is in MFC, On_command, On_message, on_notify their differences. On_notify is a macro that a control sends message processing to its parent window, On_command is a macro that handles messages for menus and toolbar items, and On_message is a macro that handles custom messages On_command used to process WM_COMMAND messages. The old-fashioned windows control sends wm_command as a notification message to the parent window. In addition, the menu, toolbar also sends a WM_COMMAND message to the frame window. On_message is primarily used to process user-defined messages. For some new Windows controls, such as Listctrl, you need to include a lot of information when sending a notification message to the parent window, WM_COMMAND has not adapted to this requirement (because WM_COMMAND's wparam and lparam are all filled up), On_ Notify is primarily used to handle the WM_NOTIFY notification messages that these new Windows controls send to the parent window.

Some common knowledge points of MFC

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.