急用

解决方案 »

  1.   

    for example//假如按纽ID是MY_ID
    //.hafx_msg void OnUpdateButtonStatus(CCmdUI* pCmdUI);//.cppBEGIN_MESSAGE_MAP(xxxx, xxxx)
    //{{AFX_MSG_MAP(CMainFrame)
    //...
    ON_UPDATE_COMMAND_UI(MY_ID, OnUpdateButtonStatus)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()void xxxx::OnUpdateButtonStatus(CCmdUI* pCmdUI) 
    {
    // TODO: Add your command update UI handler code here
      if (...)
      {
        pCmdUI->Enable(FALSE);
     }
    }
      

  2.   

    可以设个BOOL型的变量。
    CXXView::OnButton1()
    {
       m_bFlag=TRUE;
    }
    CXXView::OnUpdateButton2(CCmdUI* pCmdUI)
    {
       pCmdUI->Enable(m_bFlag?TRUE:FALSE)
    }
    另外,多说一句,对于普通的按钮(例如对话框中放置的按钮)使不能用命令状态更新消息的。应为只有菜单项和工具栏命令项,MFC才提供了命令状态更新消息。
    对于按钮,可以这样:
    CXXView::OnButton1()
    {
        GetDlgItem(ID_BUTTON2)->Enable(TRUE or FALSE);
    }
    来禁止和启动。