How to make Dialogbar

zhaozj2021-02-11  147

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 Automatic Or Adjusted. If We Want To include Controls Other Than Buttons, We need to write code to add.

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 FUNALOGBAR :: Enabledocking () DOCKTE DIALOG BAR BY CALLING FUNCONTROLBAR ():

...

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, BTH 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_top | CBRS_ALIGN_BOTTOM WHEN CALLING FUNCTION CDIALOGBAR :: Enabledocking () in Step 3 Discussed Above.

转载请注明原文地址:https://www.9cbs.com/read-6042.html

New Post(0)