I want to add all menu items
to the toolbar
but only have a subset of them showing by default (without user having to customize). This way all menu items will have icons next to them, but the toolbar won't contain the seldom used items unless users adds them.
If possible, how is that done with CMFCToolBar
?
You can define any number of 'dummy' toolbar resources in your program's resource script, like the below example, where
ID_DUMMY1
is the toolbar/bitmap resource ID (must be available to both the resource compiler and the C++ compiler) and the threeID_COMMAND_x
IDs define the menu commands that the images correspond to:Then, in your program (typically, just after you have initialized your main frame window), you can call the static member of the
CMFCToolBar
class,AddToolBarForImageCollection
to load the images from those dummy toolbars. The following will load those image in the above-defined resource:After this, every menu item with the given command(s) will show the associated image as defined in the dummy toolbar resource(s). You can have as many such toolbar resources as required, and just call the
AddToolBarForImageCollection
for each one.Note: Although I have used the same resource ID for both toolbar and bitmap resources, you can also use different IDs. So long as the arguments given in the call to
AddToolBarForImageCollection
are properly coordinated, the method will still work.