如何制作DialogBar

原创 2001年08月18日 12:25:00

 

  As we have noticed, the limitation of the tool bar is that when we design a tool bar from resource, only bitmap buttons with the same size can be included. If we try to modify the size of one bitmap button, the size of all other buttons will be automatically adjusted. If we want to include controls other than buttons, we need to write code to add them dynamically.

  If we want to implement a control bar that contains other types of common controls starting from resource editing, we need to use another type of control bar: dialog bar. In MFC, the class that can be used to implement this type of control bar is CDialogBar.

  Like tool bar, dialog bar is also derived from control bar. Both of them share some common features. For example, both types of control bars can be either docked or floated, and they all support tool tip and flyby implementation. The difference between tool bar and dialog bar is that they are designed to contain different types of controls: while tool bar is more suitable for containing a row of bitmap buttons with the same size, dialog bar can be implemented to contain any type of controls that can be used in a dialog box.

  Implementing dialog bar is similar to that of dialog box. The first step is to design a dialog-template resource. We can add buttons, edit boxes, combo boxes, even animate controls to a dialog bar.

  Dialog bar shares the same type of resource with dialog box. So when starting to create resource for dialog bar, we first need to add a “dialog” type resource to the application (In order to do this, we can execute Insert | Resource… command, then select “Dialog” from the popped up “Insert Resource” dialog box). When specifying the dialog properties, we must set “child” and “no border” styles. This can be customized in “Dialog Properties” property sheet.

  Adding a dialog bar to the application is similar to that of a tool bar. First we need to declare a variable in class CMainFrame. Then within function CMainFrame::OnCreate(), we can call the member functions of CDialogBar and CFrameWnd to create the dialog bar, set its styles and dock it.

  The following lists necessary steps of adding this dialog bar:

1)      Use CDialogBar to declare a new variable m_wndDialogBar in CMainFrame class:

class CMainFrame : public CFrameWnd

{

protected:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

...

    CDialogBar m_wndDialogBar;

...

}; 

2) In function CMainFrame::Create(), call CDialogBar::Create() to create the dialog bar window. When doing this, we need to provide the pointer of its parent window, the dialog template ID, styles and the control ID of the dialog bar. Here, the control ID could be a different number from its template ID, so long as it is not being occupied by other resources. The following code fragment shows how this function is called in the sample:

if(!m_wndDialogBar.Create(this,IDD_DIALOG_COLORBAR,CBRS_BOTTOM | CBRS_TOOLTIPS | CBRS_FLYBY,IDD_DIALOG_COLORBAR))

{

TRACE0("Failed to create toolbar/n");

return -1;

}

3) Enable docking by calling function CDialogBar::EnableDocking(), dock the dialog bar by calling function CMainFrame::DockControlBar():

...

    m_wndDialogBar.EnableDocking(CBRS_ALIGN_ANY);

    DockControlBar(&m_wndDialogBar); 

Because class CDialogBar is derived from CControlBar, in step 3, when we call function CDialogBar::EnableDocking() to enable docking for the dialog bar, we are actually calling function CControlBar::EnableDocking(). This is the same with that of tool bar. Because of this, both tool bar and dialog bar have the same docking properties.

By compiling and executing the sample at this point, we can see that the dialog bar is implemented, which is docked to the bottom border at the beginning. We can drag the dialog bar and dock it to other borders. As we do this, we may notice the difference between dialog bar and tool bar: while the size of the tool bar will be automatically adjusted when it is docked differently (horizontally or vertically), the size of dialog will not change under any condition. The reason for this is that a dialog bar usually contains irregular controls, so it is relatively difficult to adjust its size automatically. By default, dynamic size adjustment is not supported by class CDialogBar. If we want our dialog bar to support this feature, we need to override function CDialogBar::CalcDynamicLayout().

To prevent a dialog bar from taking up too much area when it is docked to left or right border, we can put restriction on the dialog bar so that it can only be docked to top or bottom border. To implement this, we can change the style flag from CBRS_ALIGN_ANY to CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM when calling function CDialogBar::EnableDocking() in step 3 discussed above.

 

 

打造完美的DialogBar

打造完美的DialogBar 打造完美的DialogBar John.Y      DialogBar相比Dialog有很多优势。因CDialogBar继承于CControlBar,因...
  • komtao520
  • komtao520
  • 2015年09月10日 16:38
  • 247

完美的DialogBar

DialogBar相比Dialog有很多优势。因CDialogBar继承于CControlBar,因此其可以Docking在窗口一边,而把CView挤压开,但是 CDialogBar 的使用并不...
  • limingmcu
  • limingmcu
  • 2014年04月24日 18:26
  • 430

VS2010上关于dialogbar的操作

一、添加并显示Dialogbar: 1.新建一个单文档MFC项目,打开资源视图,添加一个DialogBar 2.为DialogBar添加一个类MyDlgBar 3.打开MainFrm.h 添加CDi...
  • u011365452
  • u011365452
  • 2013年08月16日 16:56
  • 1254

DialogBar使用注意事项

前几天写了一个小的程序,里面用到了DialogBar,用这个东西能够起到简易的工具栏的作用,而且能够象对话框一样直接在上面添加控件使用,但是,在使用的过程中遇到了一些小的问题,拿出来大家分享一下,说不...
  • limingmcu
  • limingmcu
  • 2014年04月24日 18:30
  • 431

一步步制作根文件系统 (一)

开发环境:Ubuntu 12.04                             开发板:mini2440  256M NandFlash   64M SDRAM              ...
  • ASKLW
  • ASKLW
  • 2016年09月21日 18:47
  • 4078

把自己现在用的系统做成GHO镜像文件的几种方法

那就要手动运行GHOST了。。不过手动的和你一键备份出来的也是一样的。 手动的话在DOS运行ghost 选 Local→Partition→To Image 菜单,弹出硬盘选择窗口,开始分...
  • lixingshi
  • lixingshi
  • 2016年09月09日 12:37
  • 47536

Linux根文件系统制作

1 开发环境     宿主机:Ubuntu14.04(32bit)     开发板:Mini2440     Kernel:2.6.32.2     BusyBox:1.2.6 参考资料 [1]根...
  • Q1302182594
  • Q1302182594
  • 2016年05月08日 15:28
  • 3543

制作各种docker镜像

制作各种docker镜像及命令
  • YuZhiHui_No1
  • YuZhiHui_No1
  • 2014年11月14日 23:27
  • 27293

WebP图片制作GUI工具

WebP是Google近几年推出的新型网络图片格式,有静态和动态两种类型,其中静态webp比jpg和png的压缩率都要大,而且失真率接近于png,远胜于jpg,因为他支持8位的透明通道。而动态webp...
  • xanxus46
  • xanxus46
  • 2017年03月27日 11:37
  • 924

html文件制作最简单的方法

html文件制作最简单的方法 如何制作和编辑HTML文件?除了可以使用DreamWeaver、FrontPage等软件编写HTML文档外,其实还可以用Windows自带的记事本就可以很轻松地编辑制作h...
  • u013174689
  • u013174689
  • 2013年12月24日 19:19
  • 1690
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:如何制作DialogBar
举报原因:
原因补充:

(最多只允许输入30个字)