Question

I have a function that performs a specific action depending on the std::string value it receives.

Eg:

void performTaskOnStringValue(std::string);

Now I have a set of Ribbon Buttons (CMFCRibbonButton) that need to call this function by passing their respective text as values on button click.

I have mapped the id's of these buttons to a message map macro on_command with the button id's. All the buttons share one common id - Eg -

ID_RIBBON_BUTTON_ID

The message map is as follows

ON_COMMAND(ID_RIBBON_BUTTON_ID, &MyClass::performTaskOnStringValue);

How do I pass the button text as parameter to this function on ButtonClick?

Was it helpful?

Solution

You can't make the buttons do different operations when they all have the same ID. The command handler gets no indication of which button was pressed.

If you can assign consecutive IDs to the buttons you can use ON_COMMAND_RANGE instead. This will pass you the ID of the button, which you can pass to GetDlgItemText to get the text from the button.

OTHER TIPS

First, give each button different ids in a contiguous range.

Second, use ON_COMMAND_RANGE to map all the buttons to one handler that receives the id as a parameter.

Third, in that handler use the id to get the button text. You can then call your performTaskOnStringValue method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top