How to add buttons in the View class

 

by Jordi Binefa

http://www.binefa.net/

 

1-      To add a public member object in View class :

CButton m_Button01;

 

2-     To invoke ClassWizard (Ctrl+W)

3-     To select in “Message Maps” the …View class through the combo box

4-     Double click on WM_CREATE and click Edit Code

5-     To add under TODO:

            m_Button01.Create(_T("&Button 01"), WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON|WS_BORDER,

                        CRect(10,100,90,125),this,ID_BUTTON_01);

 

6-     To add a new identifier ID_BUTTON_01 in View/Resource Symbols

 

Now, you can execute the program.

 

7-     Between BEGIN_MESSAGE_MAP(..) and END_MESSAGE_MAP(), after //}}AFX_MSG_MAP in the …View.cpp, to add :

ON_BN_CLICKED(ID_BUTTON_01,OnButton01)

 

8-     To add a function void C…View::OnButton01() :

void C…View::OnButton01(){

            MessageBox("Hello Universe !!!!");

}

 

9-     To add a declaration of OnButton01() as a public member function of View class.

 

Now, you can execute the program.