The CToolBar Class's Member Functions
In most cases, after you have created your toolbar resource and associated its buttonswith the appropriate command IDs, you don't need to bother any more with the toolbar.
The code generated by AppWizard creates the toolbar for you, and MFC takes care of
calling the buttons' response functions for you. However, at times you might want to
change the toolbar's default behavior or appearance in some way. In those cases, you
can call on the CToolBar class's member functions, which are listed in Table 9.1 along
with their descriptions. The toolbar is accessible from the CMainFrame class as the
m_wndToolBar member variable. Usually, you change the toolbar behavior in
CMainFrame::OnCreate().
FIG. 9.8 After adding code to OnCircle(), the new toolbar button actually does something.
Table 9.1 Member Functions of the CToolBar Class
Function Description
CommandToIndex() Obtains the index of a button, given its ID
Create() Creates the toolbar
GetButtonInfo() Obtains information about a button
GetButtonStyle() Obtains a button's style
GetButtonText() Obtains a button's text label
GetItemID() Obtains the ID of a button, given its index
GetItemRect() Obtains an item's display rectangle, given its index
GetToolBarCtrl() Obtains a reference to the CToolBarCtrl object
represented by the CToolBar object
LoadBitmap() Loads the toolbar's button images
LoadToolBar() Loads a toolbar resource
SetBitmap() Sets a new toolbar button bitmap
SetButtonInfo() Sets a button's ID, style, and image number
SetButtons() Sets the IDs for the toolbar buttons
SetButtonStyle() Sets a button's style
SetButtonText() Sets a button's text label
SetHeight() Sets the toolbar's height
SetSizes() Sets the button sizes
Normally, you don't need to call the toolbar's methods, but you can achieve some
unusual results when you do, such as the extra high toolbar shown in Figure 9.9. (The
buttons are the same size, but the toolbar window is bigger.) This toolbar resulted from
a call to the toolbar object's SetHeight() member function. The CToolBar class's member
functions enable you to perform this sort of toolbar trickery, but use them with great
caution.
FIG. 9.9 You can use a toolbar object's member functions to change how the toolbar looks and acts.
No comments:
Post a Comment