Click here to Skip to main content
16,004,906 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CDC without valid hDC crashes Pin
Roger Allen23-Jan-03 2:09
Roger Allen23-Jan-03 2:09 
GeneralRe: CDC without valid hDC crashes Pin
CodeBrain23-Jan-03 23:13
CodeBrain23-Jan-03 23:13 
GeneralRe: writing a float-array into a file... Pin
Christian Graus22-Jan-03 22:29
protectorChristian Graus22-Jan-03 22:29 
GeneralRe: writing a float-array into a file... Pin
Christian Graus22-Jan-03 22:55
protectorChristian Graus22-Jan-03 22:55 
GeneralRe: writing a float-array into a file... Pin
Christian Graus22-Jan-03 23:14
protectorChristian Graus22-Jan-03 23:14 
GeneralRe: writing a float-array into a file... Pin
Christian Graus22-Jan-03 23:22
protectorChristian Graus22-Jan-03 23:22 
QuestionHow to Add afunction for Toolbar Button in VC++7 (not in VC++6) Pin
Exceter22-Jan-03 20:55
Exceter22-Jan-03 20:55 
AnswerRe: How to Add afunction for Toolbar Button in VC++7 (not in VC++6) Pin
xxhimanshu22-Jan-03 21:27
xxhimanshu22-Jan-03 21:27 
Wink | ;) hi,
this is what you are looking for..
Since Microsoft got rid of ClassWizard in VC++ 7, quite a lot of jobs have become much more difficult. This article shows how to hook up the normal click events for toolbars in VC7, and how to disable buttons programmatically, depending on context.

First, let us assume we have an SDI application created using AppWizard.

The buttons are called ID_TBRED, ID_TBGREEN, and ID_TBBLUE respectively.

Creating Event Functions for the Buttons
If we built the program above just by adding in the toolbar buttons, they would by default be disabled, which is not very useful. Now we want to add an event function to each button so they do something when clicked.

First, let's create the functions for each of them. If you are following my SDI example, it is likely you will want to define the functions in your view. 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 OnToolbarRedClick();
afx_msg void OnToolbarGreenClick();
afx_msg void OnToolbarBlueClick();

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 CDisableToolbarView::OnToolbarRedClick()
{
MessageBox("Red clicked");
}

We've now finished creating the event functions. As they stand, VC++ doesn't know what events to hook our functions up to, so we need to specify this.

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,OnToolbarRedClick)
ON_BN_CLICKED(ID_TBGREEN,OnToolbarGreenClick)
ON_BN_CLICKED(ID_TBBLUE,OnToolbarBlueClick)

By building the application, you should now see the three buttons enabled, and clicking them should show the respective message box. That's all there is to it!


cheers


Himanshu
GeneralRe: How to Add afunction for Toolbar Button in VC++7 (not in VC++6) Pin
Rage23-Jan-03 1:16
professionalRage23-Jan-03 1:16 
GeneralRe: How to Add afunction for Toolbar Button in VC++7 (not in VC++6) Pin
xxhimanshu23-Jan-03 1:33
xxhimanshu23-Jan-03 1:33 
GeneralRe: How to Add afunction for Toolbar Button in VC++7 (not in VC++6) Pin
Exceter23-Jan-03 19:11
Exceter23-Jan-03 19:11 
GeneralRe: How to Add afunction for Toolbar Button in VC++7 (not in VC++6) Pin
xxhimanshu23-Jan-03 19:41
xxhimanshu23-Jan-03 19:41 
GeneralC++ variable promotion during operator Pin
Dan Watt22-Jan-03 20:12
Dan Watt22-Jan-03 20:12 
GeneralRe: C++ variable promotion during operator Pin
Chris Losinger22-Jan-03 20:35
professionalChris Losinger22-Jan-03 20:35 
GeneralRe: C++ variable promotion during operator Pin
Dan Watt23-Jan-03 2:35
Dan Watt23-Jan-03 2:35 
GeneralRe: C++ variable promotion during operator Pin
Rage22-Jan-03 20:37
professionalRage22-Jan-03 20:37 
GeneralCant find insert section "AFX_MSG" Pin
raner22-Jan-03 19:58
raner22-Jan-03 19:58 
GeneralRe: Cant find insert section "AFX_MSG" Pin
Chris Losinger22-Jan-03 20:37
professionalChris Losinger22-Jan-03 20:37 
GeneralRe: Cant find insert section "AFX_MSG" Pin
raner22-Jan-03 21:05
raner22-Jan-03 21:05 
GeneralRe: Cant find insert section "AFX_MSG" Pin
Rage23-Jan-03 1:19
professionalRage23-Jan-03 1:19 
GeneralRe: Cant find insert section "AFX_MSG" Pin
Roger Allen23-Jan-03 2:16
Roger Allen23-Jan-03 2:16 
GeneralRe: Cant find insert section "AFX_MSG" Pin
raner23-Jan-03 4:45
raner23-Jan-03 4:45 
GeneralRe: Cant find insert section "AFX_MSG" Pin
Chris Losinger23-Jan-03 5:25
professionalChris Losinger23-Jan-03 5:25 
GeneralRe: Cant find insert section "AFX_MSG" Pin
raner23-Jan-03 5:33
raner23-Jan-03 5:33 
GeneralRe: Cant find insert section "AFX_MSG" Pin
Anonymous23-Jan-03 5:41
Anonymous23-Jan-03 5:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.