tags:

views:

819

answers:

2

I'm experimenting with adding icons to a shell extension. I have this code (sanitized for easy reading), which works:

InsertMenu(hmenu, index, MF_POPUP|MF_BYPOSITION, (UINT)hParentMenu, namestring);

The next step is this code:

HICON hIconLarge, hIconSmall;
ICONINFO oIconInfo;
ExtractIconEx("c:\\progra~1\\winzip\\winzip32.exe", 0, &hIconLarge, &hIconSmall, 1);
GetIconInfo(hIconSmall, &oIconInfo);
//???????
SetMenuItemBitmaps(hParentMenu, indexMenu-1, MF_BITMAP | MF_BYPOSITION, hbmp, hbmp);

What do I put in to replace the ?'s. Attempts to Google this knowledge have found many tips that I failed to get working. Any advice on getting this to work, especially on older machines (e.g. no .net framework, no vista) is appreciated.

+1  A: 

Vista has proper support for icons in menus, for pre Vista, you must use owner draw menu items (MF_OWNERDRAW) if you want real 16x16 full color icons

Vista style menus... Vista style+pre Vista callback

Anders
That solution requires windows XP and the .net framework. I wish to avoid both.
Brian
Did you look at the 2nd link, it has code working all the way back to win95. The point is, anything pre Vista, you really need to do the drawing yourself, so you are free to choose if you want to use GDI, GDI+ or .Net
Anders
+1  A: 

This works, though the back color is black instead of transparent.

GetIconInfo(hIconSmall, &oIconInfo);
SetMenuItemBitmaps(hmenu, uMenuIndex+i+popUpMenuCount-1, MF_BITMAP | MF_BYPOSITION, oIconInfo.hbmColor, oIconInfo.hbmColor);
Brian
Apparently, Windows is doing something clever to the icon. The orignal icon had less transparency than I thought, but Windows decided to add weird transparency. That said, the code above does end up needing a bitmap to be drawn using drawicon in between the two steps.
Brian