C++: Step 1: ExtractIconEx. Step 2: ??? Step 3: Se

2019-08-01 03:40发布

问题:

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:

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



回答2:

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);


标签: c++ winapi icons