gpt4 book ai didi

c++ - EnableMenuItem 函数不适用于参数 MF_GRAYED

转载 作者:可可西里 更新时间:2023-11-01 09:49:46 24 4
gpt4 key购买 nike

创建了一个 ATL COM 项目,通过它我将菜单项插入到右键菜单中,如下所示:

STDMETHODIMP CSimpleShlExt::QueryContextMenu (
HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd,
UINT uidLastCmd, UINT uFlags )
{
gHMenu=hmenu;
UINT uCmdID = uidFirstCmd;

// If the flags include CMF_DEFAULTONLY then we shouldn't do anything.

if ( uFlags & CMF_DEFAULTONLY )
return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, 0 );

InsertMenu ( hmenu, uMenuIndex, MF_BYPOSITION, uCmdID++, _T("Connect To Server") );
uMenuIndex++;
InsertMenu ( hmenu, uMenuIndex, MF_BYPOSITION, uCmdID++,
_T("DisConnect From Server") );
return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, 2 );
}

现在我想在用户点击它时立即禁用 Connect 子菜单,为此我正在使用 EnableSubMenuItem ,

STDMETHODIMP CSimpleShlExt::InvokeCommand ( LPCMINVOKECOMMANDINFO pCmdInfo )
{
// If lpVerb really points to a string, ignore this function call and bail out.
if ( 0 != HIWORD( pCmdInfo->lpVerb ) )
return E_INVALIDARG;


switch ( LOWORD( pCmdInfo->lpVerb) )
{
case 0:
{

TCHAR szMsg [MAX_PATH + 32];

wsprintf ( szMsg, _T("The selected file was:\n\n%s"), m_szFile );

MessageBox ( pCmdInfo->hwnd, "Connected", _T("SimpleShlExt"),
MB_ICONINFORMATION );

//InsertMenu ( hmenu, uMenuIndex, MF_STRING | MF_BYPOSITION, uCmdID++, _T("Connect => NDS") );
//EnableMenuItem(gHMenu,0,MF_GRAYED);

编辑:

EnableMenuItem(gHMenu,0,MF_DISABLED | MF_GRAYED | MF_BYPOSITION);


return S_OK;
}
break;

.....
....
...
}

但这对禁用菜单项没有帮助。我做错了什么??

最佳答案

试试这个:

EnableMenuItem(gHMenu,ITEM_ID,MF_DISABLED | MF_GRAYED);

ITEM_ID 应该是菜单项的资源 ID。

或者:

EnableMenuItem(gHMenu,ITEM_POSITION,MF_DISABLED | MF_GRAYED | MF_BYPOSITION);

其中 ITEM_POSITION 是菜单项的零索引位置。

请注意,在调用EnableMenuItem 之后,您可能需要调用DrawMenuBar 以确保显示已更新。

关于c++ - EnableMenuItem 函数不适用于参数 MF_GRAYED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3776272/

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