Hi all.
I'm currently writing a Windows Explorer Shell Extension. Everything is ok so far but I'm having trouble to insert menu items WITH MenuItemBitmaps at the end of the context menu.
Here is the code I used without the bitmaps:
HRESULT CSimpleShlExt::QueryContextMenu(HMENU hmenu, UINT /*uMenuIndex*/, UINT uidFirstCmd, UINT /*uidLastCmd*/, UINT uFlags)
{
InsertMenu(hmenu, -1, MF_SEPARATOR, uidFirstCmd++, _T(""));
InsertMenu(hmenu, -1, MF_STRING | MF_BYPOSITION, uidFirstCmd++, _T("SimpleShlExt Test Item"));
InsertMenu(hmenu, -1, MF_STRING | MF_BYPOSITION, uidFirstCmd++, _T("SimpleShlExt Test Item 2"));
return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 3); // 3 because we do have three menu items!!!
}
This code does what I want. It adds a separator and two menu items at the end of the context menu when I right click in the Windows explorer.
I can also add bitmaps to these menu items with this code:
HRESULT CSimpleShlExt::QueryContextMenu(HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd, UINT /*uidLastCmd*/, UINT uFlags)
{
// load the bitmap from the resource
HBITMAP hBitmap = (HBITMAP)LoadImage((HMODULE)_AtlBaseModule.m_hInst,
MAKEINTRESOURCE(IDB_BITMAP), IMAGE_BITMAP, 16, 16, 0);
InsertMenu(hmenu, uMenuIndex++, MF_SEPARATOR, uidFirstCmd++, _T(""));
InsertMenu(hmenu, uMenuIndex++, MF_STRING | MF_BYPOSITION, uidFirstCmd++, _T("SimpleShlExt Test Item"));
SetMenuItemBitmaps(hmenu, uMenuIndex - 1, MF_BITMAP | MF_BYPOSITION, hBitmap, hBitmap);
InsertMenu(hmenu, uMenuIndex++, MF_STRING | MF_BYPOSITION, uidFirstCmd++, _T("SimpleShlExt Test Item 2"));
SetMenuItemBitmaps(hmenu, uMenuIndex - 1, MF_BITMAP | MF_BYPOSITION, hBitmap, hBitmap);
return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 3); // 3 because we do have three menu items!!!
}
But now the menu items are placed somewhere in the middle of the context menu and not at the end. Simply setting -1
instead of uMenuIndex
doesn't work. The menu items are indeed placed at the end but the bitmaps are not shown.
Any ideas?