void CExperHallServerDlg::OnUpdateViewMainWindow(CCmdUI* pCmdUI) 
{
// TODO: Add your command update UI handler code here


pCmdUI->SetCheck(IsWindowVisible());
if(ID_VIEW_MAIN_WINDOW==pCmdUI->m_nID)
pCmdUI->SetText("隐藏窗口");
}
为什么程序运行以后没有改变菜单的CAPTION项名字呢?

解决方案 »

  1.   

    ON_UPDATE_COMMAND_UI宏用于菜单和工具条处理,比如设置菜单的 状态 (enabled/disabled, checked/unchecked 等) 。这些处理是通过调用OnUpdateXXX来实现的。可是,该宏只适用于基于文档/视窗模型的应用程序,而对于对话框,还没有提高类似的功能来处理按钮的状态而使用该宏,在处理对话框中拥有大量按钮、而这些按钮之间存在状态控制关系时尤为重要。本程序讲解该宏在对话框中实现。
      

  2.   

    类声明:
    #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 dialogclass 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_)
    类实现:
    // 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