CFrameWnd貌似会向其CView子窗口(从CWnd继承的子窗口也适用)发生此消息, 子窗口可以响应该消息来更新一些按钮控件的状态. ex:
#pragma once
// CWelcomeView
class CWelcomeWnd : public CWnd
{
public:
CWelcomeWnd();
virtual ~CWelcomeWnd();
protected:
DECLARE_MESSAGE_MAP()
afx_msg void OnIdleUpdateCmdUI();
};
// WelcomeView.cpp : 实现文件
//
#include "stdafx.h"
#include "WelcomeView.h"
#include "afxpriv.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CWelcomeView
CWelcomeView::CWelcomeView()
{
}
CWelcomeView::~CWelcomeView()
{
}
BEGIN_MESSAGE_MAP(CWelcomeView, CWnd)
ON_MESSAGE_VOID(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)
END_MESSAGE_MAP()
// CWelcomeView 消息处理程序
afx_msg void CWelcomeView::OnIdleUpdateCmdUI()
{
BOOL bEnabled = FALSE;
// 树形控件弹出菜单
// 导入导出
bEnabled = (m_nCurrTag == TAG_SIM1 ||
m_nCurrTag == TAG_SIM2 ||
m_nCurrTag == TAG_ME);
m_wndDropBtnImpExp.EnableCommand(IDC_IMPEXP, bEnabled);
m_wndDropBtnImpExp.EnableCommand(IDC_IMPCSV, bEnabled);
m_wndDropBtnImpExp.EnableCommand(IDC_IMPVCARD, bEnabled);
m_wndDropBtnImpExp.EnableCommand(IDC_EXPCSV, bEnabled);
m_wndDropBtnImpExp.EnableCommand(IDC_EXPVCARD, bEnabled);
// 复制粘贴
bEnabled = (m_nCurrTag == TAG_SIM1 ||
m_nCurrTag == TAG_SIM2 ||
m_nCurrTag == TAG_ME ||
m_nCurrTag == TAG_LOCAL);
bEnabled &= (m_wndPbList.GetSelectedCount() > 0);
m_wndDropBtnCopySave.EnableCommand(IDC_COPY1, bEnabled);
m_wndDropBtnCopySave.EnableCommand(IDC_CUT1, bEnabled);
bEnabled = (m_nCurrTag == TAG_SIM1 ||
m_nCurrTag == TAG_SIM2 ||
m_nCurrTag == TAG_ME ||
m_nCurrTag == TAG_LOCAL);
bEnabled &= (m_clipboard.size() > 0);
m_wndDropBtnCopySave.EnableCommand(IDC_PASTE1, bEnabled);
// 删除
bEnabled = (m_wndPbList.GetSelectedCount() > 0);
m_wndBtnDelete.EnableWindow(bEnabled);
// 同步
bEnabled = (m_nCurrTag == TAG_SIM1 ||
m_nCurrTag == TAG_SIM2 ||
m_nCurrTag == TAG_ME);
m_wndBtnSync.EnableWindow(bEnabled);
// 刷新
//bEnabled = (m_nCurrTag == TAG_SIM1 ||
// m_nCurrTag == TAG_SIM2 ||
// m_nCurrTag == TAG_ME);
// 添加
bEnabled = (m_nCurrTag == TAG_SIM1 ||
m_nCurrTag == TAG_SIM2 ||
m_nCurrTag == TAG_ME);
m_wndPbList.EnableTopButton(TOP_COMMAND_ADD, bEnabled);
}