Add controls and message response functions in a single MFC Document

Source: Internet
Author: User

1. Create a single MFC Document, define the cbutton m_button member variable of the View class, add the oncreate or oninitialupdate function to the *** View class, and add the oncreate or oninitialupdate function to the Function

Crect rect_button (, 60); // controls the button size and position
M_button.create ("hello", ws_child | ws_visible | ws_border, rect_button, this, idc_dynamicbutton );
M_button.showwindow (sw_shownormal );

In this way, the buttons should be displayed.

2. Add the message response function. Add afx_msg void onbtndown () to the header file ();

Add the on_bn_clicked (idc_dynamicbutton, onbtndown) link button variable between begin_message_map and end_message_map, and add the definition.

Void *** view: onbtndown ()
{
MessageBox ("hello", "helloworld", mb_ OK );
}

Or

I). Declare a message function in the header file.

Virtual lresult onmymessage (wparam, lparam );

Ii). Associate the message with the corresponding function of the message in the. cpp file.

On_bn_clicked (wm_my_message, onmymessage)

Iii). Implement the corresponding message Functions

Lresult cmyview: onmymessage (wparam, lparam)

{
// To do
Return 0;
}

In this way, the dialog box is displayed.

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.