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

别来无恙 提交于 2020-01-05 06:46:47

问题


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


来源:https://stackoverflow.com/questions/96414/c-step-1-extracticonex-step-2-step-3-setmenuitembitmaps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!