DialogBar使用注意事项

前几天写了一个小的程序,里面用到了DialogBar,用这个东西能够起到简易的工具栏的作用,而且能够象对话框一样直接在上面添加控件使用,但是,在使用的过程中遇到了一些小的问题,拿出来大家分享一下,说不定在同样的问题上能少走一点弯路

在MSDN里面的介绍如下:

dialog bar is a toolbar — a kind of control bar that can contain any kind of control. Because it has the characteristics of a modeless dialog box, aCDialogBar object provides a more powerful toolbar.

There are several key differences between a toolbar and a CDialogBar object. A CDialogBar object is created from a dialog-template resource, which you can create with the Visual C++ dialog editor and which can contain any kind of Windows control. The user can tab from control to control. And you can specify an alignment style to align the dialog bar with any part of the parent frame window or even to leave it in place if the parent is resized. The following figure shows a dialog bar with a variety of controls.

In other respects, working with a CDialogBar object is like working with a modeless dialog box. Use the dialog editor to design and create the dialog resource.

One of the virtues of dialog bars is that they can include controls other than buttons.

While it is normal to derive your own dialog classes from CDialog, you do not typically derive your own class for a dialog bar. Dialog bars are extensions to a main window and any dialog-bar control-notification messages, such as BN_CLICKED or EN_CHANGE, will be sent to the parent of the dialog bar — the main window.

For more information about dialog bars, see classCDialogBar in the Class Library Reference.

关键就是中间红色的部分,意思就是说,对于Dialog Bar上面的控件的消息响应需要交给他的父窗口来处理

所以,直接在Dialog bar上面添加控件,比如说button,然后双击button,添加消息处理函数,在运行程序后,button是灰色的,是不可以点击的,而如果想要处理这个消息,需要在mainframe里面处理消息响应。大体的思路就是这样了,实例代码如下:

首先在DialogBar上添加了一个button ID是IDC_button1

然后在mainframe的.h文件里面添加

afx_msg void OnButton1();

在cpp文件里面添加

ON_BN_CLICKED(IDC_BUTTON1, OnButton1)

以及实现代码

void CMainFrame::OnButton1()
{}

其实如此看来根本就不是什么问题,但是,当时还确实让我费了一点劲……就这么多吧

欢迎大家不吝赐教

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值