我们可以在不使用 pCmdInfo->lpVerb 的情况下执行右键吗
我不喜欢使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将菜单项标识符(或偏移量?)存储在 QueryContextMenu 中,以便稍后在 InvokeCommand 中使用:
You are supposed to store the menu item identifiers (or offsets?) in QueryContextMenu for use later in InvokeCommand: