让对话框中的菜单变灰(根据可用性而显示)

// 设定可用性(当你打开下拉菜单时便会激发UPDATE _COMMAND_UI消息,映射如下函数:
void  C *** Dlg::OnUpdateMenuLogin(CCmdUI *  pCmdUI) 
{
    
//  TODO: Add your command update UI handler code here
    pCmdUI -> Enable(mMenuActive  &   0x01 );
}
// 手动添加下面函数到你的主DIALOG里
void  C *** Dlg::OnInitMenuPopup(CMenu *  pPopupMenu, UINT nIndex, BOOL bSysMenu) 
{
    
if  ( ! bSysMenu)
    {
        ASSERT(pPopupMenu 
!=  NULL);
        
        
//  check the enabled state of various menu items
        CCmdUI state;        
        state.m_pMenu 
=  pPopupMenu;
        ASSERT(state.m_pOther 
==  NULL);
        
        state.m_nIndexMax 
=  pPopupMenu -> GetMenuItemCount();
        
for  (state.m_nIndex  =   0 ; state.m_nIndex  <  state.m_nIndexMax;
             state.m_nIndex
++ )
        {
            state.m_nID 
=  pPopupMenu -> GetMenuItemID(state.m_nIndex);
            
if  (state.m_nID  ==   0 )
                
continue //  menu separator or invalid cmd - ignore it
                
            ASSERT(state.m_pOther 
==  NULL);
            ASSERT(state.m_pMenu 
!=  NULL);
            
if  (state.m_nID  ==  (UINT) - 1 )
            {
                
//  possibly a popup menu, route to first item of that popup
                state.m_pSubMenu  =  pPopupMenu -> GetSubMenu(state.m_nIndex);
                
if  (state.m_pSubMenu  ==  NULL  ||
                    (state.m_nID 
=  state.m_pSubMenu -> GetMenuItemID( 0 ))  ==   0   ||
                    state.m_nID 
==  (UINT) - 1 )
                {                                 
                    
continue //  first item of popup can't be routed to
                }
                state.DoUpdate(
this , FALSE);   //  popups are never auto disabled
            }
            
else
            {
                
//  normal menu item
                
//  Auto enable/disable if command is _not_ a system command
                state.m_pSubMenu  =  NULL;
                state.DoUpdate(
this , state.m_nID  <   0xF000 );
            }
        }
    }
 }
// 还得添加消息映射:
BEGIN_MESSAGE_MAP(CcontrolDlg, CDialog)
ON_WM_INITMENUPOPUP()
END_MESSAGE_MAP()

// 现在便会按照你要打开菜单时它的可用性而显示是否变灰:)

你可能感兴趣的:(对话框)