locked
How to add an icon to a menu item. RRS feed

  • Question

  • I wanted to add an icon to a menu item, but could not do that. Can anybody exp-lain me how to do step by step using Visual studio 2005.

    I have a menu item already created. I have a icon which is also previously created. Now, I just need to steps so that the icons shows up while displaying that particular menu item. I went thru the MSDN help but could not make it out and that did not help much.

     

    Regards,

    Arindam.

     

    Monday, January 21, 2008 1:27 PM

Answers

  • Depends on what kind of menu are you talking about. SetMenuItemBitmaps should be called if the menu is not custom drawn.

    Monday, January 21, 2008 10:44 PM

All replies

  • Depends on what kind of menu are you talking about. SetMenuItemBitmaps should be called if the menu is not custom drawn.

    Monday, January 21, 2008 10:44 PM
  • The menu is not a custom. It is general men. Say i want to add the icon in File->open menu. I have created the icon in the resources. How would I add that icon so that while running, the menu shows up the icon.

     

    Tuesday, January 22, 2008 5:31 AM
  • Arindam Chakrabarti said:

    I wanted to add an icon to a menu item, but could not do that. Can anybody exp-lain me how to do step by step using Visual studio 2005.

    I have a menu item already created. I have a icon which is also previously created. Now, I just need to steps so that the icons shows up while displaying that particular menu item. I went thru the MSDN help but could not make it out and that did not help much.

     

    Regards,

    Arindam.

     

    Hi Can any one tell me how to add an icon or an image in a popupmenu created dynamically(Using createmenu and createpopupmenu and appendmenu functions).

    I did the following to create the menu and add image to it.

    hSubMenu = CreatePopupMenu();         
    hChildMenu = CreateMenu();
              
    AppendMenu(hSubMenu, MF_STRING | MF_POPUP, (UINT)hChildMenu, "&File");          
    AppendMenu(hChildMenu, MF_STRING, id, "Open");

    HBITMAP hShareBmp = LoadBitmap(_Module.GetResourceInstance(),294 ); // where 294 is the //resource id of the image.
    SetMenuItemBitmaps(hSubMenu,id,MF_BYCOMMAND,hShareBmp,NULL);   

    I can see the image in the menu, but the resolution when i mouseover to it is very bad. The complete image is becoming dark bluish color.

    I need to load the image and menu items dynamically when the user click menu type button.
    Can any one  help in this regard...

    Thanks in advance...
    koti

     


           

    Tuesday, June 10, 2008 10:55 AM
  • Hi thanks for the info...

           But i am not able to compile the code. It is giving an error  "The procedure entry point SHGetStockIconInfo could not be located in the dynamic link libaray SHELL32.dll".

    Any ideas to proceed further.

    regards
    koti
    Wednesday, June 11, 2008 7:19 AM
  • the technique is similar but unfortunately he does have some Vista specific functions in there.  I'll see if I can get it going in XP later this afternoon and let you know what functions to change.

    Wednesday, June 11, 2008 12:26 PM
  • I got it going but unfortunately there's a lot that has to be changed around.  The basic technique is in the place in the code that calls TrackPopupMenuEx.   You can follow the code and incorporate some ideas into your own.
    Friday, June 13, 2008 3:26 AM
  • Thanks TED,
          Thanks for ur interest. I will go through it and get back to you.


    Friday, June 13, 2008 6:42 AM
  • Hi Ted,

        I made some modifications in the source code. In the function TrackPopupIconMenuEx(...) i have uncommented LoadIconMetric(...) and used LoadIcon(...) function to get "hIcon" and also uncommented the
    entire  _SetDialogIcon(HWND hdlg, SHSTOCKICONID siid) method. Then it is working fine. I am giving how the generated menu is looking before mouseover and after mouseover.


    I want the menu icon to be looking as original even when we mouseover to it. Do you have any idea to do it.

    regards,
    koti.

    Friday, June 13, 2008 7:20 AM


  • I tried using the code from ShellRevealed, but I had problems as well.  Since I only needed a single 32 bit icon that I create on the fly using CreateIcon, I just use DrawIconEx without using BeginPaintBuffer, EndPaintBuffer, or his function to add the alpha channel since my icon already has an alpha channel.  The problem is I cannot get it to work when the system color depth is less than 32 bit.  Any thoughts would be greatly appreciated.
    Friday, January 30, 2009 4:37 AM