I am having trouble putting a bitmap image on a menuitem directly. I notice that those menuitems that also have a toolbar item with a bitmap image (e.g., IDM_FILE_NEW) have that image automatically inserted in their MENUITEMs. But when I try to add a bitmap to a MENUITEM that does not, I fail to make one appear. The code below shows how I tried to do it, pretty much the same as in the article
The file contains a 13 x 13 bitmap, as required by querying the GetMenuCheckMarkDimensions() function. The IDW_MAIN_MENU contains a view menu popup (I am modifying your FormDocView sample), to which I have added a MENUITEM to bring up a color choice dialog to set the background color.
On execution, no assert activates, so the file is loading and setting ok, I suppose. But when the mouse selects the view submenu on the menu bar, the Background Color MENUITEMshows a blank grey image only (not CHECKED) or a check mark (CHECKED).
What am I doing wrong?
Thank you for any help you have time to provide. It is much appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For some unknown reason, your message was held up in pending. I'm not sure why. Anyway, moving on ...
The menu items for frames use owner drawing by default. As a result, any changes attempted with SetMenuItemBitmaps will be ignored. The SetMenuItemBitmaps function is only intended to replace the image displayed for checkmarks in menu items which is why it is 13x13. I expect this is not what you intend.
The two functions used by Win32++ to associate images with menu items are CFrame::AddMenuIcons and CFrame::AddMenuIcon. The AddMenuIcon function can be used to associate a 16x16 icon resource to the menu item. The AddMenuIcons function is used to associate a bitmap containing several images to menu items.
AddMenuIcons is demonstrated in the Browser sample.
AddMenuIcon is demonstrated in the DockTabbedMDI, MDIFrameDemo and TabDemo samples.
Best regards,
David
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That worked! Thank you very much. I spent several days trying everything but that. Interesting that the MSDN description is so misleading. Even when I made the bmp a 13x13 black/white image, as a check mark replacement, it ignored it. BTW: I also found that the menuitem must be unchecked for the AddMenuItem() function to work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am having trouble putting a bitmap image on a menuitem directly. I notice that those menuitems that also have a toolbar item with a bitmap image (e.g., IDM_FILE_NEW) have that image automatically inserted in their MENUITEMs. But when I try to add a bitmap to a MENUITEM that does not, I fail to make one appear. The code below shows how I tried to do it, pretty much the same as in the article
CMenu::SetMenuItemBitmaps
https://msdn.microsoft.com/en-us/library/a17fx6as.aspx
In resource.rc I correspond a bitmap ID with the file in which it appears
IDM_COLOR_CHOICE BITMAP DISCARDABLE "res/crayon13.bmp"
The file contains a 13 x 13 bitmap, as required by querying the GetMenuCheckMarkDimensions() function. The IDW_MAIN_MENU contains a view menu popup (I am modifying your FormDocView sample), to which I have added a MENUITEM to bring up a color choice dialog to set the background color.
I've tried both blank and CHECKED versions. The bitmap does not overwrite the image area in either case. In the CHECKED case, the check mark appears.
In the CMainFrame.h declaration file, I define
In the CMainFrame.cpp implementation file, in OnCreate(), as in the MSDN Library example, I enter
On execution, no assert activates, so the file is loading and setting ok, I suppose. But when the mouse selects the view submenu on the menu bar, the Background Color MENUITEMshows a blank grey image only (not CHECKED) or a check mark (CHECKED).
What am I doing wrong?
Thank you for any help you have time to provide. It is much appreciated.
Hi Robert,
For some unknown reason, your message was held up in pending. I'm not sure why. Anyway, moving on ...
The menu items for frames use owner drawing by default. As a result, any changes attempted with SetMenuItemBitmaps will be ignored. The SetMenuItemBitmaps function is only intended to replace the image displayed for checkmarks in menu items which is why it is 13x13. I expect this is not what you intend.
The two functions used by Win32++ to associate images with menu items are CFrame::AddMenuIcons and CFrame::AddMenuIcon. The AddMenuIcon function can be used to associate a 16x16 icon resource to the menu item. The AddMenuIcons function is used to associate a bitmap containing several images to menu items.
AddMenuIcons is demonstrated in the Browser sample.
AddMenuIcon is demonstrated in the DockTabbedMDI, MDIFrameDemo and TabDemo samples.
Best regards,
David
That worked! Thank you very much. I spent several days trying everything but that. Interesting that the MSDN description is so misleading. Even when I made the bmp a 13x13 black/white image, as a check mark replacement, it ignored it. BTW: I also found that the menuitem must be unchecked for the AddMenuItem() function to work.
Hi David,
thank your for this information, I was also looking for a way to add icons in a context menu.
I have one question though as I looked on other examples how it's done and then in DockTabbedMDI I noticed:
Is this "GetApp()->" needed here? I think not, as we should use already the correct CWinApp object, right?
Best regards,
Daniel