Search on the Internet a lot of information, found to be able to display the button on a single document, but is unable to respond to events,
For a long time, found M_pbutton->create () to be placed in the C***view class of OnCreate ().
But in VS2008 new single document program C***view class does not overload the OnCreate () function, to
Overload the function yourself, which can be generated using the wizard. Here is a detailed procedure:
A new SDI (single document) program button, the wizard generates the Cbuttonview class, and other classes
There are also buttonview.h,buttonview.cpp two files, and of course other documents.
Second, add the CButton pointer variable in the Cbuttonview class M_pbutton
Third, add OnCreate function in Cbuttonview class, generate Wm_create message function through Class Wizard.
Iv. adding in the Resoure.h file
#define IDC_TEST 1000
Add a button-generating function to the OnCreate function of the Cbuttonview class
int cbuttonview::oncreate (lpcreatestruct lpcreatestruct)
{
if (cview::oncreate (lpcreatestruct) = =-1)
return-1;
TODO: Add your own dedicated creation code here
M_pbutton = new CButton;
M_pbutton->create ("Please click", ws_child| Ws_visible, CRect (100,100,200,140), this,idc_test);
return 0;
}
VI. Add the test function to the Cbuttonview class, which can be generated by the wizard
In ButtonView.h
Class Cbuttonview:public CView
{
..............
Public
afx_msg int OnCreate (lpcreatestruct lpcreatestruct);
void test (void);
}
In ButtonView.cpp
void Cbuttonview::test (void)
{
AfxMessageBox ("You clicked on Me");
}
Vii. adding a message map to the Cbuttonview class, ButtonView.cpp file
Begin_message_map (Cbuttonview, CView)
..........
Add a click Message
On_bn_clicked (Idc_test, &cbuttonview::test)
On_wm_create ()
End_message_map ()
Eight, run the program, in the SDI customer area has a "please click" button, click on the pop-up "You clicked me" message box