我们可以在不使用 pCmdInfo->lpVerb 的情况下执行右键吗

发布于 2024-09-25 01:25:56 字数 1512 浏览 5 评论 0原文

我不喜欢使用 pCmdInfo->lpVerb 但我的问题是当我们动态创建右键单击子菜单时我们将如何处理这种情况。例如,我有以下场景:

if(strcmp(cRegKeyVal,"Connected")==0)
    {
        //g_bConnectStatus=TRUE;
        InsertMenu ( m_hSubmenu , 0,  MF_BYPOSITION|MF_GRAYED, m_uCmdID++, _T("Connect") );
        InsertMenu ( m_hSubmenu , 1,  MF_BYPOSITION, m_uCmdID++, _T("DicConnect") );
        InsertMenu ( m_hSubmenu , 2,  MF_BYPOSITION, m_uCmdID++, _T("Configure") );
        InsertMenu ( m_hSubmenu , 3,  MF_BYPOSITION, m_uCmdID++, _T("Menu4") );
        InsertMenu ( m_hSubmenu , 4,  MF_BYPOSITION, m_uCmdID++, _T("About") );
    }
    else
    {
        //g_bConnectStatus=FALSE;
        InsertMenu ( m_hSubmenu , 0,  MF_BYPOSITION, m_uCmdID++, _T("Connect") );
        InsertMenu ( m_hSubmenu , 3,  MF_BYPOSITION, m_uCmdID++, _T("Help") );
        InsertMenu ( m_hSubmenu , 4,  MF_BYPOSITION, m_uCmdID++, _T("About") );
    }
..  
..  
InsertMenuItem ( hmenu, uMenuIndex, TRUE, &mii );
}

现在,如果我将 pCmdInfo->lpVerb 与 switch case 一起使用,如下所示,则 Case 1 正在执行 无论我单击DisConnect(在上述代码片段的 If 条件下插入菜单项)或 Help > (菜单项插入 Else 部分,如上面的代码片段)

switch ( LOWORD( pCmdInfo->lpVerb) )
        {
        case 0:
            {
            //Your Logi for Case-0
            }
            break;
        case 1:
            {
        //Your Logi for Case-I      
            }
        break;
      }

I am not agnaist using pCmdInfo->lpVerb but my problem is how will we handle the situation when we create the rightclick submenus dynamically. For example, I have the following scenario:

if(strcmp(cRegKeyVal,"Connected")==0)
    {
        //g_bConnectStatus=TRUE;
        InsertMenu ( m_hSubmenu , 0,  MF_BYPOSITION|MF_GRAYED, m_uCmdID++, _T("Connect") );
        InsertMenu ( m_hSubmenu , 1,  MF_BYPOSITION, m_uCmdID++, _T("DicConnect") );
        InsertMenu ( m_hSubmenu , 2,  MF_BYPOSITION, m_uCmdID++, _T("Configure") );
        InsertMenu ( m_hSubmenu , 3,  MF_BYPOSITION, m_uCmdID++, _T("Menu4") );
        InsertMenu ( m_hSubmenu , 4,  MF_BYPOSITION, m_uCmdID++, _T("About") );
    }
    else
    {
        //g_bConnectStatus=FALSE;
        InsertMenu ( m_hSubmenu , 0,  MF_BYPOSITION, m_uCmdID++, _T("Connect") );
        InsertMenu ( m_hSubmenu , 3,  MF_BYPOSITION, m_uCmdID++, _T("Help") );
        InsertMenu ( m_hSubmenu , 4,  MF_BYPOSITION, m_uCmdID++, _T("About") );
    }
..  
..  
InsertMenuItem ( hmenu, uMenuIndex, TRUE, &mii );
}

Now If I am using pCmdInfo->lpVerb with switch case , as demonstrated below, then Case 1 is getting executed Whether I click on DisConnect (Menu Item Inserted in If condition in above code snippet) or Help (Menu Item Inserted in Else part as above code snippet)

switch ( LOWORD( pCmdInfo->lpVerb) )
        {
        case 0:
            {
            //Your Logi for Case-0
            }
            break;
        case 1:
            {
        //Your Logi for Case-I      
            }
        break;
      }

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

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

发布评论

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

评论(1

夏夜暖风 2024-10-02 01:25:56

您应该将菜单项标识符(或偏移量?)存储在 QueryContextMenu 中,以便稍后在 InvokeCommand 中使用:

QueryContextMenu()
{
    m_uConnectId = m_uCmdID++;
    InsertMenu( m_hSubMenu, "Connect" );
    m_uHelpId = m_uCmdID++;
    InsertMenu( m_hSubMen, "Help" );
}

InvokeCommand()
{
    ULONG uCmdID = LOWORD( pCmdInfo->lpVerb );
    if( uCmdID == m_uConnectId )
    {
        // do "Connect"
    }
    else if( uCmdID == m_uHelpId )
    {
        // do "Help"
    }
}

You are supposed to store the menu item identifiers (or offsets?) in QueryContextMenu for use later in InvokeCommand:

QueryContextMenu()
{
    m_uConnectId = m_uCmdID++;
    InsertMenu( m_hSubMenu, "Connect" );
    m_uHelpId = m_uCmdID++;
    InsertMenu( m_hSubMen, "Help" );
}

InvokeCommand()
{
    ULONG uCmdID = LOWORD( pCmdInfo->lpVerb );
    if( uCmdID == m_uConnectId )
    {
        // do "Connect"
    }
    else if( uCmdID == m_uHelpId )
    {
        // do "Help"
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文