Hicham
Hicham

Reputation: 979

how to map an mfc toolbar button event with a class method?

I'm using an MFC application with a toolbar.

I need to use a button of this toolbar in some class.

But, i don't find how to map the toolbar button events to methods of my class.

I saw in the property menu that i can map an event to a method. but there the name the the button is not in the events list.

The button is already used in other classes.

So how to map a toolbar button in my class ?

Upvotes: 1

Views: 1972

Answers (1)

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10425

The only classes that receive toolbar messages are view windows, the mainframe, the document and the CWinApp. Toolbar/Menu messages are not routed to other classes. Your question would be clearer if you explain what kind of class you are trying to add the toolbar message handler into.

Another problem is that the Visual Studio wizard assumes that there is a menu command with the same ID as each toolbar button. So it only lists menu IDs, not toolbar IDs that have no matching menu command. But you can easily map a toolbar button to a class method without the wizard's help by putting a line like this in the class message map:

    ON_COMMAND(ID_NEW_TOOLBUTTON, OnNewToolbutton)

But it will only work in the above mentioned classes that receive toolbar messages.

Upvotes: 1

Related Questions