views:

47

answers:

1

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;
      }
+1  A: 

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"
    }
}
Luke
@Luke, Tried with the Code . While assigning m_ConnectID=m_uCmdID++, m_ConnectID contains a value something like 3081 while pCmdInfo->lpVerb=contains the values(may be Index Values ) like 0,1,3..So the Compare yields no matchs. Also the InsertMenu is not taking 2 Arguments.
Subhen
It was pseudo-code for illustrative purposes. I guess lpVerb contains the index instead of the identifier, so you need to store the indexes instead of the identifiers.
Luke
@Luke, In That case the Index will be same for 1st 3 Submenu Items in If and Else Condition.
Subhen
Yes, but that doesn't matter. Your shell extension is only going to build one of the menus at a time. You set a flag indicating which menu you created in QueryContextMenu and then check that flag in InvokeCommand so you interpret the indexes correctly.
Luke