Menu Bars and Toolbars
How to dock a toolbar to another toolbar in the same row?
Here is the code snippet that allows you to dock a m_wndToolBar2 toolbar to the right side of a m_wndToolBar1 toolbar in the same row. CRect wrAlreadyDockedBar;
m_wndToolBar1.GetWindowRect( &wrAlreadyDockedBar );
wrAlreadyDockedBar.OffsetRect( 1, 0 );
DockControlBar(&m_wndToolBar2,AFX_IDW_DOCKBAR_TOP,&wrAlreadyDockedBar);
RecalcLayout();
How to display tooltips for menu items?
The tooltip is implemented in the CExtPopupMenuTipWnd class and allows you to display tooltips of several shape types, which are listed in the CExtPopupMenuTipWnd::e_tip_style_t enumeration: enum e_tip_style_t
{
__ETS_NONE = 0,
__ETS_BALLOON = 1,
__ETS_BALLOON_NO_ICON = 2,
__ETS_RECTANGLE = 3,
__ETS_RECTANGLE_NO_ICON = 4,
__ETS_INV_RECTANGLE = 5,
__ETS_INV_RECTANGLE_NO_ICON = 6,
};The global variable CExtPopupMenuWnd::g_eTtsClassicMenu specifies the current tooltip type. By default, it is set to CExtPopupMenuTipWnd::__ETS_NONE and the tooltip is hidden. So, to display the tooltip of a certain type, set CExtPopupMenuWnd::g_eTtsClassicMenu to one of the CExtPopupMenuTipWnd::e_tip_style_t enumeration values. For example: CExtPopupMenuWnd::g_eTtsClassicMenu = CExtPopupMenuTipWnd::__ETS_BALLOON
How to set a palette layout for a toolbar?
By default, toolbar buttons takes up one row when the toolbar is docked or floating. When it is floating, you can resize it to rearrange buttons in two or more rows but, if you dock it back, its one row layout will be restored back. You can however set up the toolbar so it has a fixed size and a multiple row layout (also known as a palette layout) even when it is docked (see the figure below). To turn this mode on, set its m_bPaletteMode property to true. Because this extends the functionality provided by MFC's TBBS_WRAPPED, the following wrap flags were added to the CExtBarButton class: __EVT_FLOAT__EVT_HORZ__EVT_VERT
This allows you to set up three different layouts for when the toolbar is floating, docked horizontally and docked vertically. Please note that in this mode, the toolbar always has a fixed size. The typical way of setting up a multi row layout for toolbar may look like as follows: m_wndPalette.m_bPaletteMode = true; // turn on palette mode for toolbar
int nBtnIdx = m_wndPalette.GetButtonsCount(); // get count of toolbar buttons (you may need it)
// set wrap flags for a particular button i:
m_wndPalette.GetButton( i )->SetWrap( CExtBarButton::__EVT_FLOAT );
m_wndPalette.GetButton( i )->SetWrap( CExtBarButton::__EVT_HORZ ); You can find an example of setting up a palette layout in the DRAWCLI sample.
How to use a small icon in menus and a large icon in toolbars for the same command?
Because any particular command cannot be assigned icons of different sizes, you should use different command identifiers in toolbars and menus and assign the same command handlers to them. The steps below outline how you can create a small menu item (16x16) and a large toolbar button (32x32) which will be working as a single command (e.g. File | Open): 1) Add a menu item (ID_FILE_OPEN_16X16) to the IDR_MAINFRAME menu resource. 2) Add a new icon (ID_FILE_OPEN_32X32) to the IDR_MAINFRAME toolbar resource with 32x32 icons. 3) Create a toolbar resource (IDR_MAINFRAME_SMALL_ICONS ) and add a small version (16x16) of the ID_FILE_OPEN_32X32 icon to this resource. Specify ID_FILE_OPEN_16X16 as is its ID. 4) Initialize the IDR_MAINFRAME toolbar using the CExtToolControlBar::LoadToolbar() method. This method indirectly updates the command manager with |