C++ MFC 如何在菜单的更新函数之外将菜单有效或无效

2025-04-07 11:59:09
推荐回答(5个)
回答1:

void CCmdUI::Enable(BOOL bOn)
{
    if (m_pMenu != NULL)
    {
        if (m_pSubMenu != NULL)
            return; // don't change popup menus indirectly

        ASSERT(m_nIndex < m_nIndexMax);
        m_pMenu->EnableMenuItem(m_nIndex, MF_BYPOSITION |
            (bOn ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
    }
    else
    {
        // enable/disable a control (i.e. child window)
        ASSERT(m_pOther != NULL);

        // if control has the focus, move the focus before disabling
        if (!bOn && (::GetFocus() == m_pOther->m_hWnd))
            m_pOther->GetParent()->GetNextDlgTabItem(m_pOther)->SetFocus();
        m_pOther->EnableWindow(bOn);
    }
    m_bEnableChanged = TRUE;
}

回答2:

你可以设置一个标志,在更新函数中检测标志再决定是否enable

回答3:

好久不写mfc细节记不得了

在窗口类里加成员变量m_flag,在菜单A响应函数里面m_flag = fase;

然后在菜单B的on-update-ui响应函数里面写if(m_flag) cmdUI->enable(TRUE)...

回答4:

有函数,分析下CMenu类

回答5:

GetDlgItem(菜单ID)->Enable=false