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.