How to Add an Event Handler for Toolbar Button in VC++7
-
;)hi, do it like this!!!!!!!!!!!!!! Open the header file for your view (double-click the class name in Class View), this is CDisableToolbarView in the example. Okay; we need to write the declarations for our three functions; these would be as so: afx_msg void OnToolbarButtonClick(); That's all we need in our header, so we can close that and open our cpp file. For each of the three functions declared above, we need to create a function defintition like the one below. void CToolbarView::OnToolbarButtonClick() { MessageBox("Red clicked"); } Toward the top of the cpp file you will see a block of code starting with BEGIN_MESSAGE_MAP. Within these lines we can hook the click events up to our functions. Between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP lines, add the following three lines: ON_BN_CLICKED(ID_TBRED,OnToolbarButtonClick) thats it.. cheers Himanshu
-
;)hi, do it like this!!!!!!!!!!!!!! Open the header file for your view (double-click the class name in Class View), this is CDisableToolbarView in the example. Okay; we need to write the declarations for our three functions; these would be as so: afx_msg void OnToolbarButtonClick(); That's all we need in our header, so we can close that and open our cpp file. For each of the three functions declared above, we need to create a function defintition like the one below. void CToolbarView::OnToolbarButtonClick() { MessageBox("Red clicked"); } Toward the top of the cpp file you will see a block of code starting with BEGIN_MESSAGE_MAP. Within these lines we can hook the click events up to our functions. Between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP lines, add the following three lines: ON_BN_CLICKED(ID_TBRED,OnToolbarButtonClick) thats it.. cheers Himanshu
You may also try the easy solution : Add your button in the ressource editor. Doubleclick on it to open properties. Give it a name (for instance ID_OPENFILE). Close the window, go open the class wizard. Select your button name in the list on the right and handle the corresponding message. All the stuff given by Himanshu will be added automatically. Oh, BTW, Himanshu, feel free to put your code into a <pre> environment, it is far more readable. ;P ~RaGE();