我不是使用pCmdInfo->lpVerb
的agnaist但我的问题是当我们动态创建rightclick子菜单时我们将如何处理这种情况。例如,我有以下情况:
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
开关案例,如下所示,那么Case 1
正在执行我是否点击 DisConnect
(菜单项已插入)在如果条件在上面的代码段中)或 Help
(菜单项插入 Else 部分,如上面的代码段)
switch ( LOWORD( pCmdInfo->lpVerb) )
{
case 0:
{
//Your Logi for Case-0
}
break;
case 1:
{
//Your Logi for Case-I
}
break;
}
答案 0 :(得分:1)
您应该在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"
}
}