Windows シェルのコンテキスト メニューに複数のメニュー項目を追加しようとしています。これまでに行ったのは次のコードです。これにより、アイテムをサブメニューとして追加し、メインのコンテキストメニューに表示させます。ここに写真があります:
何か案は?どうも!
STDMETHODIMP CFileFavShellExt::QueryContextMenu (HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd, UINT uidLastCmd, UINT uFlags )
{
// This is not our business.
if (CMF_DEFAULTONLY & uFlags)
{
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
}
UINT uID = uidFirstCmd;
if (!InsertMenu(hmenu, uMenuIndex, MF_SEPARATOR | MF_BYPOSITION, 0, NULL))
{
return HRESULT_FROM_WIN32(GetLastError());
}
// Creating my menu.
HMENU hSubmenu = CreateMenu();
InsertMenu (hSubmenu, 0, MF_BYPOSITION, uID++, _T("Add to bookmarks 1"));
InsertMenu (hSubmenu, 1, MF_BYPOSITION, uID++, _T("Add to bookmarks 2"));
MENUITEMINFO mii = { sizeof(mii) };
mii.fMask = MIIM_SUBMENU | MIIM_ID | MIIM_STRING;
mii.hSubMenu = hSubmenu;
mii.fType = MFT_STRING;
mii.dwTypeData = _T("Bla");
mii.wID = uID++;
if (!InsertMenuItem(hmenu, uMenuIndex, TRUE, &mii))
{
return HRESULT_FROM_WIN32(GetLastError());
}
if (!InsertMenu(hmenu, uMenuIndex, MF_SEPARATOR | MF_BYPOSITION, 0, NULL))
{
return HRESULT_FROM_WIN32(GetLastError());
}
return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, uID - uidFirstCmd);
}
編集:サブメニューを使用せずに別の方法を試しましたが、まだ運がありません。「メニュー1」しか得られず、「メニュー2」がありません...
STDMETHODIMP CFileFavShellExt::QueryContextMenu (HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd, UINT uidLastCmd, UINT uFlags )
{
// This is not our business.
if (CMF_DEFAULTONLY & uFlags)
{
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
}
UINT uID = uidFirstCmd;
UINT pos = uMenuIndex;
MENUITEMINFO mii = { sizeof(mii) };
mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID | MIIM_STATE;
mii.fType = MFT_STRING;
mii.dwTypeData = _T("Menu 1");
mii.fState = MFS_ENABLED;
mii.wID = uID++;
if (!InsertMenuItem(hmenu, pos++, TRUE, &mii))
{
return HRESULT_FROM_WIN32(GetLastError());
}
MENUITEMINFO mii2 = { sizeof(mii) };
mii2.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID | MIIM_STATE;
mii2.fType = MFT_STRING;
mii2.dwTypeData = _T("Menu 2");
mii2.fState = MFS_ENABLED;
mii2.wID = uID++;
if (!InsertMenuItem(hmenu, pos++, TRUE, &mii2))
{
return HRESULT_FROM_WIN32(GetLastError());
}
return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, uID - uidFirstCmd);
}