我使用 C++ 和 win32 编程编写了一个 shell 扩展 dll 上下文菜单程序。开发环境是 Visual Studio 2008 和 2010。在下面的示例代码中,我试图只为主菜单添加菜单图标。主菜单未显示菜单图标。(我需要为所有菜单项添加图标。)。
请更正以下代码。
QueryContextMenu(HMENU hmenu, UINT /*uInd*/, UINT idCmdFirst, UINT /*idCmdLast*/, UINT /*uFlags*/ )
{
int id = 1;
HBITMAP hBitmap = NULL;
hBitmap = (HBITMAP)LoadImage((HMODULE)_AtlBaseModule.m_hInst,MAKEINTRESOURCE(IDB_MYBITMAP), IMAGE_BITMAP, 12, 12, 0);
HMENU submenu = CreatePopupMenu();
AppendMenu(submenu, MF_STRING|MF_ENABLED, uidCmdFirst + id++, L"XP");
AppendMenu(submenu, MF_STRING|MF_ENABLED,uidCmdFirst + id++, L"VISTA");
AppendMenu(submenu, MF_STRING|MF_ENABLED,uidCmdFirst + id++, L"Win 7");
InsertMenu(hmenu, 4,MF_BYPOSITION|MF_POPUP, UINT(submenu), L"Windows");
SetMenuItemBitmaps(hmenu,id++, MF_BITMAP, hBitmap,hBitmap);
return id;
}