Main functions
1. ctoolbar: setsizes (size sizebutton, size sizeimage)
Used to set the size of the tool button and the size of the bitmap above it. this function has two parameters, sizebutton is used to specify the button size, and sizeimage is used to specify the bitmap size. note that the Cx and Cy fields of these two parameters must be greater than zero, and the width (CX) of sizebutton must be at least 7 larger than the width of sizeimage, and the height (CY) at least 6.
2. ctoolbar: setbuttontext (INT nindex, lpctstr lpsttext)
This function is used to set the text displayed on the tool button. nindex is used to specify the tool button to be set based on the 0 index value (including delimiter) in the toolbar ), that is, the nindex + 1 tool button will be set. lpsttext is the text to be displayed.
3. ctoolbar: enabletooltips (bool benable)
This function is used to set or cancel the tooltips function of the tool button.
4. cmainframe: showcontrolbar (ccontrolbar * pbar, bool bshow, bool bdelay)
This function is used to set whether to display the toolbar or status bar.
Pbar: pointer to the configured toolbar or status bar object
If bshow is set to true, the toolbar or status bar is displayed. Otherwise, the toolbar or status bar is hidden;
Bdelay: True, the delay time is displayed; otherwise, the toolbar or status bar is displayed immediately.
Implementation
1. Add variable
Size Type member variable m_sizemax, used to store the maximum size of the button
2. Add static arrays at the beginning of the implementation file of the cmainframe class to store text labels as follows:
# Ifdef _ debug
# Define new debug_new
# UNDEF this_file
Static char this_file [] = _ file __;
# Endif
Static tchar * texttips [] = {"new", "open", "Storage", "", "cut", "copy", "Paste ","", "print", "", "about", ""}; // This sentence is added
3. Use classwizard to add a member function for cmainframe: void cmainframe: updatemedilbar (); To update the toolbar.
Void cmainframe: updatemedilbar ()
{
Crect rect;
Size sizebutton, sizeimage;
M_sizemax.cx = 0;
M_sizemax.cy = 0;
// Obtain the maximum size
For (INT I = 0; I <m_wndtoolbar.getcount (); I ++)
{
M_wndtoolbar.setbuttontext (I, texttips);
M_wndtoolbar.getitemrect (I, rect );
M_sizemax.cx = _ max (rect. Size (). CX, m_sizemax.cx );
M_sizemax.cy = _ max (rect. Size (). Cy, m_sizemax.cy );
}
// Set the button size
Sizebutton. Cx = m_sizemax.cx;
Sizebutton. Cy = m_sizemax.cy;
Sizeimage. Cx = 16;
Sizeimage. Cy = 15;
M_wndtoolbar.setsizes (sizebutton, sizeimage );
Showcontrolbar (& m_wndtoolbar, false, false );
Showcontrolbar (& m_wndtoolbar, true, false );
M_wndtoolbar.redrawwindow ();
}
4. In the cmainframe: oncreate () function, add the following before return 0;Code:
Updatemedilbar (); // update a toolbar