1.
#define TBBS_WRAPPED MAKELONG(0, TBSTATE_WRAP)
TBBS代表的意思是toolbar button styles
其实实现CToolBar分多行显示的方式在VS给出的例子ctrlbars就有很详细的介绍。
但自己写了一个仿的例子,结果失败,工具条怎么也不分行显示。最后一点点的缩小出错代码的范围,才发现要想分行显示,必须将CToolBar的style设为CBRS_SIZE_FIXED (CBRS代表control bar styles,CControlBar::SetBarStyle中要用到CBRS,除此外,从CControlBar派生的各种子类也各自定义了CBRS,参见子类的Create) 。
后来发现原来MSDN上有,也看过下面这一段,但因为看得不仔细,所以没理解透。
/////////////////////////////////////////////////////
As of Visual C++ version 4.0, you can make it possible for users of your application to resize floating toolbars dynamically. Typically, a toolbar has a long, linear shape, displayed horizontally. But you can change the toolbar's orientation and its shape. For example, when the user docks a toolbar against one of the vertical sides of the frame window, the shape changes to a vertical layout. It's also possible to reshape the toolbar into a rectangle with multiple rows of buttons.
You can:
-
Specify dynamic sizing as a toolbar characteristic.
-
Specify fixed sizing as a toolbar characteristic.
To provide this support, there are two new toolbar styles for use in your calls to the CToolBar::Create member function. They are:
-
CBRS_SIZE_DYNAMIC Control bar is dynamic.
-
CBRS_SIZE_FIXED Control bar is fixed.
The size dynamic style lets your user resize the toolbar while it is floating, but not while it is docked. The toolbar "wraps" where needed to change shape as the user drags its edges.
The size fixed style preserves the wrap states of a toolbar, fixing the position of the buttons in each column. Your application's user can't change the shape of the toolbar. The toolbar wraps at designated places, such as the locations of separators between the buttons. It maintains this shape whether the toolbar is docked or floating. The effect is a fixed palette with multiple columns of buttons.
You can also use CToolBar::GetButtonStyle to return a state and style for buttons on your toolbars. A button's style determines how the button appears and how it responds to user input; the state tells whether the button is in a wrapped state.
///////////////////////////////////////////////////////////////////////
动态风格可以让用户在工具条浮动时改变它的形状。工具栏处于停靠状态时则不能改变。用户拖动工具栏边框时工具栏会自动通过“断行”来调整形态。
固定风格不会“断行”,而是固定每行各按钮的位置。用户不能通过拖动边框改变工具栏的形态。工具栏只以设定好的位置“断行”并不再改变,无论它是浮动,还是停靠……
所以,要想使用TBBS_WRAPPED来分多行显示工具条,就必须设好CBRS_SIZE_FIXED。
2.
在找这个问题的资料时,在网上发现了别一种做法,可以将工具条分多行显示:
CRect rcNew;
m_wndToolBar.GetToolBarCtrl().SetRows(m_wndToolBar.GetCount()/2,true,&rcNew);
// FloatControlBar(&m_wndToolBar,CPoint(0,0),CBRS_ALIGN_RIGHT);
RecalcLayout();
Invalidate();
这里也要设置CBRS_SIZE_FIXED才能起作用。
浙公网安备 33010602011771号