怎么控制让工具条上面的某些按钮灰掉不能用? 一个基于对话框的程序,我在上面放了一个CToolBar工具条,对应一个菜单;现在想让这个工具条上面的某些按钮灰掉不能用,不知道应该怎么做?我看了CToolBar类没有成员函数可以设置某些按钮是否可用.各位高手帮忙一哈,感激不尽! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把工具条上按钮相应的菜单项disable就可以了。 不行啊.我这样试过.我这个程序是基于对话框的,好像是对话框不会自动去响应那个UPDAGE_COMMAND_UI消息.不知道有没有办法可以让工具条上的按钮灰掉呢,如果可以我自己手动控制也行. 在对话框中使用ON_UPDATE_COMMAND_UION_UPDATE_COMMAND_UI宏用于菜单和工具条处理,比如设置菜单的 状态 (enabled/disabled, checked/unchecked 等) 。这些处理是通过调用OnUpdateXXX来实现的。可是,该宏只适用于基于文档/视窗模型的应用程序,而对于对话框,还没有提高类似的功能来处理按钮的状态而使用该宏,在处理对话框中拥有大量按钮、而这些按钮之间存在状态控制关系时尤为重要。本程序讲解该宏在对话框中实现。本程序从CDialog派生了一个类CCmdUIDialog,实现了必要的代码来调用OnUpdateXXX函数。在使用时,你可以直接从 CCmndUIDialog派生,而不从CDialog派生新类,并手工添加ON_UPDATE_COMMAND_UI宏到新类。 类声明:#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{// Constructionpublic: CCmdUIDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL); CCmdUIDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL); CCmdUIDialog(); BOOL ContinueModal();// Implementationprotected: // 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_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CCmdUIDialog dialogCCmdUIDialog::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_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CCmdUIDialog message handlers注意:本类使用了MFC没有公开的成员函数CCmdUI::DoUpdate。请参见一个例子:dialog\commandui_dialog目录。第二种实现方法在不派生一个新类的情况下,重载下面两的函数中任一个函数:BOOL ::PreTranslateMessage( MSG* pMsg ){UpdateDialogControls( this, TRUE );return CDialog::PreTranslateMessage( pMsg );}或者: BOOL ::ContinueModal( ){UpdateDialogControls( this, TRUE );return CDialog::ContinueModal( );}注意:ContinueModal调用比PreTranslateMessage频繁五倍。 http://community.csdn.net/Expert/topic/4677/4677892.xml?temp=.8642694 m_wndToolBar.GetToolBarCtrl().EnableButton(ID_BUTTON_XX, FALSE); 请教:CView 上如何实现类似office的文本框编辑 求双目是标准图及其标准视差图 书上的例子,不知道我错哪里了 程序异常退出 向喜欢研究计算机内核的高手请教,100分! 如何对弹出菜单进行消息处理? 出接口的客户端实现问题 com的线程模式 怎样在一个CSplitterWnd中嵌如另一个CSplitterWnd? dll导出函数的问题 与光盘上的access数据库动态建立ODBC,为何不行? 打开进程的问题:
ON_UPDATE_COMMAND_UI宏用于菜单和工具条处理,比如设置菜单的 状态 (enabled/disabled, checked/unchecked 等) 。这些处理是通过调用OnUpdateXXX来实现的。可是,该宏只适用于基于文档/视窗模型的应用程序,而对于对话框,还没有提高类似的功能来处理按钮的状态而使用该宏,在处理对话框中拥有大量按钮、而这些按钮之间存在状态控制关系时尤为重要。本程序讲解该宏在对话框中实现。本程序从CDialog派生了一个类CCmdUIDialog,实现了必要的代码来调用OnUpdateXXX函数。在使用时,你可以直接从 CCmndUIDialog派生,而不从CDialog派生新类,并手工添加ON_UPDATE_COMMAND_UI宏到新类。 类声明:
#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
注意:本类使用了MFC没有公开的成员函数CCmdUI::DoUpdate。请参见一个例子:dialog\commandui_dialog目录。第二种实现方法
在不派生一个新类的情况下,重载下面两的函数中任一个函数:
BOOL ::PreTranslateMessage( MSG* pMsg )
{
UpdateDialogControls( this, TRUE );
return CDialog::PreTranslateMessage( pMsg );
}或者:
BOOL ::ContinueModal( )
{
UpdateDialogControls( this, TRUE );
return CDialog::ContinueModal( );
}注意:ContinueModal调用比PreTranslateMessage频繁五倍。