流云の剑舞秋风

吾生也有涯 而知也无涯

博客园 首页 新随笔 联系 订阅 管理
//设定可用性(当你打开下拉菜单时便会激发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()

//现在便会按照你要打开菜单时它的可用性而显示是否变灰:)
posted on 2005-05-27 08:14  流云  阅读(1701)  评论(1编辑  收藏  举报