在command事件中加入:
GetMenu()->EnableMenuItem(IDM_XXX,MF_DISABLED|MF_GRAYED); //禁用MF_DISABLED,可用MF_ENABLE  
GetMenu()->CheckMenuItem(IDM_XXX,MF_CHECKED); //打勾MF_CHECKED ...消去MFUNCHECKED

解决方案 »

  1.   

    将对话框改为无模式就可以了!
    不用DoModal();
      

  2.   

    我是过了,用create创建无模式的对话框也不行啊!谁能说说这就竟是什么原因?怎样才能正确收到并处理update_command_ui??急啊!
      

  3.   

    我想起CFrameWnd有一成员m_bAutoEnableMenu( 没拼错吧)但不知道基于对话框的程序会有什么东西
      

  4.   

    会和m_bAutoMenuEnable有关系吗?这个变量只是决定没有ON_UPDATE_COMMAND_UI和ON_COMMAND处理函数的菜单是否自动设为无效吧
      

  5.   

    why ,说出来让我们也知道呀
      

  6.   

    ON_UPDATE_COMMAND_UI是在点击菜单项和消息对列为空时(IDLE)发送的,但基于对话框的项目自己处理消息,在IDLE时并不发送该消息。实际上,在对基于话框项目中,主对话框根本收不到WM_ENTERIDLE,这是因为:用DoModal创建的DIALOG用自己的消息处理函数RunModalLoop,他在IDLE时将WM_ENTERIDLE发到对话框的父窗口。但主对话框没父窗口,当然收不到。这样当然也不会有机会发送ON_UPDATE_COMMAND_UI了。
    解决方法见http://www.csdn.net/expert/topic/110/110122.shtm
      

  7.   

    看这里 呵呵
                         You will have used the ON_UPDATE_COMMAND_UI macro in MFC with your various menu commands. This macros is used to
                         implement the message handler for the UPDATE_COMMAND_UI "message" sent by the MFC framework. This message allows you
                         to set the state (enabled/disabled, checked/unchecked etc) of your menu and toolbar items by calling the various OnUpdateXXX
                         functions that you supply.                     Quite often, it would be useful to use this same "auto-update" facility with the controls of a dialog box. Unfortunately, MFC does not
                         provide this functionality for you. In this article, I present a dialog class, derived from CDialog, that allows you to use the familiar
                         ON_UPDATE_COMMAND_UI macros with any control on a dialog box.                      This approach has the advantage of centralising your dialog controls state logic and is very useful for complicated dialogs where the state
                         of many controls is determined by the state of other controls on the dialog.                     The class, CCmdUIDialog, implements the necessary code to call your OnUpdateXXX functions. You simply derive your dialog class
                         from CCmndUIDialog instead of CDialog, and manually add the ON_UPDATE_COMMAND_UI macros to your class.                     Class declaration:                     #if !defined(AFX_CMDUIDIALOG_H__7D35F4B8_7531_11D1_8FA7_000000000000__INCLUDED_)
                         #define AFX_CMDUIDIALOG_H__7D35F4B8_7531_11D1_8FA7_000000000000__INCLUDED_                     #if _MSC_VER >= 1000
                         #pragma once
                         #endif // _MSC_VER >= 1000
                         // CmdUIDialog.h : header file
                         //                      /////////////////////////////////////////////////////////////////////////////
                         // CCmdUIDialog dialog                     class CCmdUIDialog : public CDialog
                         {
                         // Construction
                         public:
                                 CCmdUIDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL);
                                 CCmdUIDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL);
                                 CCmdUIDialog();
                                 BOOL ContinueModal();                     // Implementation
                         protected:                             // Generated message map functions
                                 //{{AFX_MSG(CCmdUIDialog)
                                 // NOTE: the ClassWizard will add member functions here
                                 //}}AFX_MSG
                                 DECLARE_MESSAGE_MAP()
                         };                     //{{AFX_INSERT_LOCATION}}
                         // Microsoft Developer Studio will insert additional declarations immediately before the previous line.                     #endif // !defined(AFX_CMDUIDIALOG_H__7D35F4B8_7531_11D1_8FA7_000000000000__INCLUDED_)
                         Class Implementation:                     // CmdUIDialog.cpp : implementation file
                         //                     #include "stdafx.h"
                         #include "delme.h"
                         #include "CmdUIDialog.h"                     #ifdef _DEBUG
                         #define new DEBUG_NEW
                         #undef THIS_FILE
                         static char THIS_FILE[] = __FILE__;
                         #endif                     /////////////////////////////////////////////////////////////////////////////
                         // CCmdUIDialog dialog
                         CCmdUIDialog::CCmdUIDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
                                 : CDialog(lpszTemplateName, pParentWnd)
                         {
                         }                     CCmdUIDialog::CCmdUIDialog(UINT nIDTemplate, CWnd* pParentWnd)
                                 : CDialog(nIDTemplate, pParentWnd)
                         {
                         }                     CCmdUIDialog::CCmdUIDialog()
                         {
                         }
                         BOOL CCmdUIDialog::ContinueModal()
                         {
                                 // Iterate all child windows and instruct to update themselves
                                 CWnd* pWndChild=GetWindow(GW_CHILD);
                                 int iIndex=0;
                                 while (NULL!=pWndChild)
                                 {                                     CCmdUI state;
                                         state.m_nID=::GetWindowLong(*pWndChild, GWL_ID);
                                         state.m_nIndex=iIndex++;
                                         state.m_pOther=pWndChild;                                     // ***CCmdUI::DoUpdate is undocumented MFC***
                                         state.DoUpdate(this, FALSE);                                     pWndChild=pWndChild->GetWindow(GW_HWNDNEXT);
                                 }                             // Must call the base class
                                 return CDialog::ContinueModal();
                         }                     BEGIN_MESSAGE_MAP(CCmdUIDialog, CDialog)
                                 //{{AFX_MSG_MAP(CCmdUIDialog)
                                         // NOTE: the ClassWizard will add message map macros here
                                 //}}AFX_MSG_MAP
                         END_MESSAGE_MAP()                     /////////////////////////////////////////////////////////////////////////////
                         // CCmdUIDialog message handlers
                         To use the class and update handlers                     First, derive your dialog class from CCmdUIDialog instead of CDialog. Next, add update command handlers for each control you
                         require this feature for, using the following technique:                     Enter the name of the update function in the protected section of your dialog header file                     Each update function has the signature void OnUpdateXXX(CCmdUI* pCmdUI); where XXX might describe the control for this
                         handler. These update functions should be places immediatley after the //}}AFX_MSG comment in your header file. This will ensure that
                         all of the command handlers are grouped together.                     Add a ON_UPDATE_COMMAND_UI macro in your dialog source (.cpp) file.                     This macro takes the resource ID of the dialog control and the name if the update function to call. For a dialog control called
                         IDC_CHECK1 with a handler function called OnUpdateCheck1 , the macro entry would read                             ON_UPDATE_COMMAND_UI(IDC_CHECK1, OnUpdateCheck1)                     This handler should appear between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP macros and after the
                         //}}AFX_MSG_MAP entry.                     Implement the update function                     Implement the logic you require in your update function, using the passed CCmdUI pointer to update your dialog control. The passed
                         CCmdUI pointer is based on the dialog control that this habdler is called for.                     The attached example application displays a dialog that used the technique described here and also shows how to update more than one
                         control using the same handler function.
      

  8.   

    多谢elang(忆郎)提供的方法,不错的解决方案!!
      

  9.   

    TO elang(忆郎):
    这种方法应该是好的,可是我试验怎么老是不成功?重载的ContinueModal调用了,但ON_UPDATE_COMMAND_UI还是老样子!你试验成功的吗?或有没有实例?能不能发给我[email protected],先谢了!!