EnableMenuItem 函数无法使用参数 MF_GRAYED

发布于 2024-09-24 18:05:01 字数 1828 浏览 5 评论 0原文

创建了一个 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;

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

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

Have created a ATL COM project through which I am inserting Menu Items to The rightclick menu like this:

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

Now I wan to Disable the Connect submenu as soon as the user clicks on it and for this I am using 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);

Edit:

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


            return S_OK;
            }
            break;

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

But this is not helping with disabling the Menu Item. What am I doing Wrong??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初熏 2024-10-01 18:05:01

试试这个:

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 以确保显示已更新。

Try this:

EnableMenuItem(gHMenu,ITEM_ID,MF_DISABLED | MF_GRAYED);

ITEM_ID should be the resource ID of the menu item.

Or:

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

where ITEM_POSITION is the zero-indexed position of the menu item.

Note that after calling EnableMenuItem, you may need to call DrawMenuBar to ensure that the display has been updated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文