I searched high and low for information about icons in menus. The only thing I found was a lot of people discussing how to use SetMenuItemBitmaps(). Unfortunately, SetMenuItemBitmaps() is for setting the check mark bitmaps, the checked and unchecked image, of the menu item. I tried this in my CMfcRibbonBar button menu but it didn’t do anything. I tried extracting icons from toolbar bitmaps, loading images directly from files and resources, and still nothing worked.
From what I read, SetMenuItemBitmaps() never seemed to work for anyone else. It if did, they were never the ones answering the questions about it.
Finally, I downloaded an MFC sample from Microsoft, opened the project, and saw there in the ribbon bar, a button with a menu WITH ICONS! Much to my surprise, they did not call the AppendMenu() function for the menu, they called AddSubItem() and added a button. Code will be more clear.
// Create the button CMFCRibbonButton* pButton = new CMFCRibbonButton( -1, "The Button", 58, -1 ); // Create a CMenu object. CMenu *pMenu = new CMenu; // Create a popup menu attached to the CMenu object. pMenu->CreatePopupMenu(); // Add a menu item. pMenu->AppendMenu( MF_STRING, 12345, "Menu Item" ); // Failed attempts to set the icons or images were here. ... // Associate the menu with the button. pButton->SetMenu( pMenu->GetSafeHmenu() );
// Create the button. CMFCRibbonButton* pButton = new CMFCRibbonButton( -1, "The Button", 58, -1 ); // Create a CMenu object. CMenu *pMenu = new CMenu; // Create a popup menu attached to the CMenu object. pMenu->CreatePopupMenu(); // Add a sub item to the button, not the menu! Notice the image index! pButton->AddSubItem( new CMFCRibbonButton( 12345, "Menu Item", 63 ) ); // Associate the menu with the button. pAlignButton->SetMenu( Menu.GetSafeHmenu() );
I apologize if this code doesn’t compile exactly as shown but I took out a lot of code that was distracting from the actual solution.
The difference is subtle. Instead of adding items to the menu, sub items are added to the button. The AddSubItem() function accepts an index for the image to use.
I am about to test to see if the menu is even needed. I will also debug the MFC code to find out why this works. But the end result is exactly what I need.
Menu With Icons
It would be nice if this were documented better. I will also point out here that there are two reasons that I did this: Reason one is because these items take up too much room in the ribbon bar itself and reason two is that these and two check boxes that are in the same panel did not look good together. The check boxes are now above the menu button above where I cropped the picture.
Save Simulation Position
I also added a new capability which is a Stop button to stop the simulation and then save the current simulation state as the new starting state of the mechanism. In other words, where the simulation is stopped determines the locations of all of the links and connectors. A user could use the manual control method to move to a specific location in the simulation and then use this new feature to save the mechanism in that position.
It’s handy if the mechanism is build based on some drawing that doesn’t represent the actual start point of the mechanism.
The button looks like the stop button with a pin in it. I’m still playing around with the location of the button in the panel.
New Pin Button
New App Icon
And finally, I made a better icon for the program. This one is a bit more artistic than the last or at least a little more modern looking to me.