MFC对话框程序中添加工具栏及工具栏上的Button响应UPDATE_COMMAND_UI消息
2004-11-17 21:27
537 查看
对话框中添加工具栏及工具栏上的Button响应UPDATE_COMMAND_UI消息
在对话框程序中添加工具栏其实很简单,网上能找到很多的例子。一般的步骤就是:1、在资源中添加工
具栏资源;2、在对话框类中定义一个工具栏变量;3、在对话框的OnInitDialog函数中Create工具栏。程
序如下:
在对话框类中定义工具栏成员变量:
CToolBar m_ToolBar;
在OnInitDialog函数中Create之:
if(!m_ToolBar.CreateEx(this, TBSTYLE_FLAT,
WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_SIZE_DYNAMIC)
||!m_ToolBar.LoadToolBar(IDR_TOOLBAR_GRAPHICS))
{
TRACE0(_T("创建工具条失败/n"));
return FALSE;
}
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
但是要让对话框中的工具栏响应UPDATE_COMMAND_UI消息,做到按下保持的状态仅仅重载
UPDATE_COMMAND_UI消息并使用SetCheck是不行的,因为此时的工具栏上的按钮属性为普通的按钮,可以
通过下面的方法测试:
if(m_ToolBar.GetButtonStyle(0) == TBBS_BUTTON)
{
AfxMessageBox("This is Button Style");
}
必须添加以下的设置:
m_ToolBar.SetButtonStyle(0,TBBS_CHECKBOX);
m_ToolBar.SetButtonStyle(1,TBBS_CHECKBOX);
SetButtonStyle函数的原型及其相关的说明:(引自MSDN)
1、void SetButtonStyle( int nIndex, UINT nStyle );
Parameters
nIndex
Index of the button or separator whose information is to be set.
nStyle
The button style. The following button styles are supported:
TBBS_BUTTON Standard pushbutton (default)
TBBS_SEPARATOR Separator
TBBS_CHECKBOX Auto check-box button
TBBS_GROUP Marks the start of a group of buttons
TBBS_CHECKGROUP Marks the start of a group of check-box buttons
Remarks
Call this member function to set the style of a button or separator, or to group buttons. A
button's style determines how the button appears and how it responds to user input.
2、还有一种修改Button属性的函数
void SetButtonInfo( int nIndex, UINT nID, UINT nStyle, int iImage );
Parameters
nIndex
Index of the button or separator whose information is to be set.
nID
The value to which the button’s command ID is set.
nStyle
The new button style. The following button styles are supported:
TBBS_BUTTON Standard pushbutton (default)
TBBS_SEPARATOR Separator
TBBS_CHECKBOX Auto check-box button
TBBS_GROUP Marks the start of a group of buttons
TBBS_CHECKGROUP Marks the start of a group of check-box buttons
iImage
New index for the button’s image within the bitmap.
Remarks
Call this member function to set the button's command ID, style, and image number. For
separators, which have the style TBBS_SEPARATOR, this function sets the separator's width in
pixels to the value stored in iImage.
For information on bitmap images and buttons, see the CToolBar Overview and
CToolBar::LoadBitmap.
在对话框程序中添加工具栏其实很简单,网上能找到很多的例子。一般的步骤就是:1、在资源中添加工
具栏资源;2、在对话框类中定义一个工具栏变量;3、在对话框的OnInitDialog函数中Create工具栏。程
序如下:
在对话框类中定义工具栏成员变量:
CToolBar m_ToolBar;
在OnInitDialog函数中Create之:
if(!m_ToolBar.CreateEx(this, TBSTYLE_FLAT,
WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_SIZE_DYNAMIC)
||!m_ToolBar.LoadToolBar(IDR_TOOLBAR_GRAPHICS))
{
TRACE0(_T("创建工具条失败/n"));
return FALSE;
}
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
但是要让对话框中的工具栏响应UPDATE_COMMAND_UI消息,做到按下保持的状态仅仅重载
UPDATE_COMMAND_UI消息并使用SetCheck是不行的,因为此时的工具栏上的按钮属性为普通的按钮,可以
通过下面的方法测试:
if(m_ToolBar.GetButtonStyle(0) == TBBS_BUTTON)
{
AfxMessageBox("This is Button Style");
}
必须添加以下的设置:
m_ToolBar.SetButtonStyle(0,TBBS_CHECKBOX);
m_ToolBar.SetButtonStyle(1,TBBS_CHECKBOX);
SetButtonStyle函数的原型及其相关的说明:(引自MSDN)
1、void SetButtonStyle( int nIndex, UINT nStyle );
Parameters
nIndex
Index of the button or separator whose information is to be set.
nStyle
The button style. The following button styles are supported:
TBBS_BUTTON Standard pushbutton (default)
TBBS_SEPARATOR Separator
TBBS_CHECKBOX Auto check-box button
TBBS_GROUP Marks the start of a group of buttons
TBBS_CHECKGROUP Marks the start of a group of check-box buttons
Remarks
Call this member function to set the style of a button or separator, or to group buttons. A
button's style determines how the button appears and how it responds to user input.
2、还有一种修改Button属性的函数
void SetButtonInfo( int nIndex, UINT nID, UINT nStyle, int iImage );
Parameters
nIndex
Index of the button or separator whose information is to be set.
nID
The value to which the button’s command ID is set.
nStyle
The new button style. The following button styles are supported:
TBBS_BUTTON Standard pushbutton (default)
TBBS_SEPARATOR Separator
TBBS_CHECKBOX Auto check-box button
TBBS_GROUP Marks the start of a group of buttons
TBBS_CHECKGROUP Marks the start of a group of check-box buttons
iImage
New index for the button’s image within the bitmap.
Remarks
Call this member function to set the button's command ID, style, and image number. For
separators, which have the style TBBS_SEPARATOR, this function sets the separator's width in
pixels to the value stored in iImage.
For information on bitmap images and buttons, see the CToolBar Overview and
CToolBar::LoadBitmap.
相关文章推荐
- 一些常见的GUI对应的程序名称整理
- 从客户端检测到有潜在危险的Request.Form 值
- 我被Build撞了一下腰
- JBuilderX和JBuilder 2005的字体光标问题
- ANT安装、配置
- 消息队列(Message Queue)简介及其使用
- [music]Canon and Gigue in D major
- 消息队列(Message Queue)简介及其使用
- MFC对话框程序中添加工具栏及工具栏上的Button响应UPDATE_COMMAND_UI消息
- 对输入法及字体的操作
- NGNc的S60移植基本完成,进入测试!
- ADO.NET Quiz 之对象序列化
- WinEdt设置 Q&A(更新中)
- 尝鲜微软新桌面主题——Energy Blue
- 尝鲜微软新桌面主题——Energy Blue
- seablue的音乐很好听.
- Request.QueryString的所有值
- 关于使用docuemnt.write问题
- Lucene是一套全文检索的API
- 尝鲜微软新桌面主题——Energy Blue