gpt4 book ai didi

c++ - 如何将多个菜单项添加到 windows shell 扩展?

转载 作者:行者123 更新时间:2023-11-28 00:44:17 25 4
gpt4 key购买 nike

我正在尝试将多个菜单项添加到 Windows shell 的上下文菜单中。到目前为止我所做的是以下代码,这将我的项目添加为子菜单,而我希望它们位于主上下文菜单中。这是一张照片: What I have vs What I want

有什么想法吗?谢谢!

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”不见了......

enter image description here

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

最佳答案

子菜单在那里是因为您正在添加它。

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

这会添加“Bla”子菜单,您已将其他项目添加到该子菜单中。要删除子菜单,只需删除此代码,然后将其他项目直接添加到主菜单即可。

关于c++ - 如何将多个菜单项添加到 windows shell 扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17158401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com