分享
 
 
 

如何制作DialogBar

王朝vc·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

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:

...

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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有