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 />

void CBarDoc::OnButtons(UINT uID)<br />

{<br />

m_uCurrentBtn=uID;<br />

}<br />

void CBarDoc::OnUpdateButtons(CCmdUI* pCmdUI)<br />

{<br />

pCmdUI->SetRadio(pCmdUI->m_nID == m_uCurrentBtn);<br />

}<br />

Please compare the above code with the implementation in section 1.2. When we ask Class Wizard to<br />

add message mapping macros, it always adds them between //{{AFX_MSG comments. Actually, these<br />

comments are used by the Class Wizard to locate macros. To distinguish between the work done by<br />

ourselves and that done by Class Wizard, we can add the statements outside the two comments.<br />

1.5. Fixing the Size of Tool Bar<br />

Remember in section 1.1, when creating the color bar, we used CBRS_SIZE_DYNAMIC style:<br />

m_wndToolBar.SetBarStyle<br />

(<br />

m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC<br />

);<br />

This allows the size of a tool bar to change dynamically. When the bar is floating or docked to top or<br />

bottom border of the client area, the buttons will have a horizontal layout. If the bar is docked to left or<br />

right border, they will have a vertical layout.<br />

Sometimes we may want to fix the size of the tool bar, and disable the dynamic layout feature. This<br />

can be achieved through specifying CBRS_SIZE_FIXED flag instead of CBRS_SIZE_DYNAMIC flag when calling<br />

function CToolBar::SetBarStyle(…).<br />

By default, the buttons on the tool bar will have a horizontal layout. If we fix the size of the tool bar,<br />

its initial layout will not change throughout application’s lifetime. This will cause the tool bar to take up too<br />

much area when it is docked to either left or right border of the client area (Figure 1-6).<br />

Instead of fixing the layout this way, we may want to wrap the tool bar from the second button, so the<br />

width and height of the tool bar will be roughly the same at any time (Figure 1-7).<br />

Figure 1-6: Docking a tool bar with horizontal layout to the<br />

left or right border will take up too much window area<br />

16

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

Saved successfully!

Ooh no, something went wrong!