11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 1. Tool Bar and Dialog Bar<br />

Click here to<br />

set styles<br />

Don’t let a dialog<br />

bar have border<br />

Change window<br />

style to “Child”<br />

Figure 1-10. Set dialog bar styles<br />

Button IDC_BUTTON_A and<br />

IDC_BUTTON_B<br />

Edit box<br />

IDC_EDIT<br />

Combo box<br />

IDC_COMBO<br />

Figure 1-11. Dialog bar template resource<br />

3) Enable docking by calling function CDialogBar::EnableDocking(…), dock the dialog bar by calling<br />

function CMainFrame::DockControlBar(…):<br />

……<br />

……<br />

……<br />

m_wndDialogBar.EnableDocking(CBRS_ALIGN_ANY);<br />

DockControlBar(&m_wndDialogBar);<br />

Because class CDialogBar is derived from CControlBar, in step 3, when we call function<br />

CDialogBar::EnableDocking(…) to enable docking for the dialog bar, we are actually calling function<br />

CControlBar::EnableDocking(…). This is the same with that of tool bar. Because of this, both tool bar and<br />

dialog bar have the same docking properties.<br />

By compiling and executing the sample at this point, we can see that the dialog bar is implemented,<br />

which is docked to the bottom border at the beginning. We can drag the dialog bar and dock it to other<br />

borders. As we do this, we may notice the difference between dialog bar and tool bar: while the size of the<br />

tool bar will be automatically adjusted when it is docked differently (horizontally or vertically), the size of<br />

dialog will not change under any condition. The reason for this is that a dialog bar usually contains<br />

irregular controls, so it is relatively difficult to adjust its size automatically. By default, dynamic size<br />

adjustment is not supported by class CDialogBar. If we want our dialog bar to support this feature, we need<br />

to override function CDialogBar::CalcDynamicLayout(…).<br />

To prevent a dialog bar from taking up too much area when it is docked to left or right border, we can<br />

put restriction on the dialog bar so that it can only be docked to top or bottom border. To implement this,<br />

we can change the style flag from CBRS_ALIGN_ANY to CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM when<br />

calling function CDialogBar::EnableDocking(…) in step 3 discussed above.<br />

1.9. Resizable Dialog Bar<br />

Because dialog bar can contain more powerful controls than tool bar, we could use it to implement<br />

control bars with more flexibility. To make user-friendly interface, sometimes we may really want to<br />

dynamically change a dialog bar’s size.<br />

24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!