Hi,
I use ItemFindPosForCmdID to find a separator (TYPE/ID_SEPARATOR = 0) in a popup menu. The menu is structured as the following:
- TYPE_POPUP -> (leads to two CmdIDs)
- CMD_ID_1
- TYPE_SEPARATOR
- CMD_ID_2
- CMD_ID_3
The problem is that ItemFindPosForCmdID retrieves 0 as position of the separator, instead of 2. Reading a suggestion you gave in an other topic, I used the following code to check it out:
TRACE( "\r\n\r\nTRACING MENU COMMANDS (BEGIN) ====================\r\n" );
for( INT nIndex = 0; nIndex < pPopup->ItemGetCount(); nIndex ++ )
{
const CExtPopupMenuWnd::MENUITEMDATA & mi = pPopup->ItemGetInfo( nIndex );
UINT nCmdID = mi.GetCmdID();
TRACE3( "index = %d, ID = %d, equal to ID_TO_FIND = %s\r\n", nIndex, nCmdID, nCmdID == CExtPopupMenuWnd::TYPE_POPUP ? "YES" : "NO" );
}
TRACE( "TRACING MENU COMMANDS (END) ====================\r\n\r\n\r\n" );
I discovered that ItemFindPosForCmdID retrieves 0 (position) because GetCmdID returns 0 (id) instead of 0xFFFFFFFF (TYPE_POPUP).
The problem seems to occur in the first GetCmdNode call in GetCmdID:
UINT CExtPopupMenuWnd::MENUITEMDATA::GetCmdID() const
{
// if( IsSeparator()
// || IsInplaceEdit()
// )
// return ( (UINT) (IDC_STATIC) );
if( IsPopup() )
{
#if (!defined __EXT_MFC_NO_CUSTOMIZE)
CExtCustomizeCmdTreeNode * pNode =
( const_cast < MENUITEMDATA * > ( this ) )
=> -> GetCmdNode();
if( pNode == NULL )
return 0;
ASSERT_VALID( pNode );
if( ( pNode->GetFlags() & __ECTN_TBB_COLOR ) != 0 )
return 0;
// if( ( pNode->GetFlags() & __ECTN_TBB_UNDO_REDO ) != 0 )
// return pNode->GetCmdID();
// if( ( pNode->GetFlags() & __ECTN_TBB_SEPARATED_DROPDOWN ) == 0 )
// return 0;
// CExtCmdItem * pCmdItem =
// g_CmdManager->CmdGetPtr(
// g_CmdManager->ProfileNameFromWnd( GetCmdReceiver() ),
// pNode->GetCmdID()
// );
// if( pCmdItem != NULL )
// return pCmdItem->m_nCmdID;
if( ( pNode->GetFlags() & (__ECTN_TBB_UNDO_REDO|__ECTN_TBB_SEPARATED_DROPDOWN) ) != 0 )
return pNode->GetCmdID();
#endif // (!defined __EXT_MFC_NO_CUSTOMIZE)
return ( (UINT) (IDC_STATIC) );
} // if( IsPopup() )
return m_nCmdID;
}
That call (the one with the right-pointed arrow on the left) return a null pNode, forcing the method to return 0 (and consequentely causing the misinterpretation of a TYPE_POPUP as a TYPE_SEPARATOR).
Additional information: this problem does not occur with Prof-UIS 2.90 Freeware. With the freeware library version GetCmdID returns correctly -1 in corrispondence of the TYPE_POPUP.
What do you think the problem depends on?
Thanks,
Tom