Rediger

Del via


Using Toolbar Controls

This topic contains implementation details and example code for using toolbar controls in your applications.

In this section

Topic Description
How to Create Toolbars
To create a toolbar, use the CreateWindowEx function, specifying the TOOLBARCLASSNAME window class. The resulting toolbar initially contains no buttons. Add buttons to the toolbar by using the TB_ADDBUTTONS or TB_INSERTBUTTON message. You must send the TB_AUTOSIZE message after all the items and strings have been inserted into the control, to cause the toolbar to recalculate its size based on its content.
How to Create Vertical Toolbars
The key to creating a vertical toolbar is to include CCS_VERT in the window style, and to set the TBSTATE_WRAP style for each button.
How to Dynamically Label Toolbar Buttons
You can assign text to an existing button by using the TB_SETBUTTONINFO message.
How to Display Tooltips for Buttons
When you specify the TBSTYLE_TOOLTIPS style, the toolbar creates and manages a tooltip control. The tooltip control is hidden and appears only when users move the pointer over a toolbar button and leave it there for approximately one second.
How to Handle Drop-down Buttons
A drop-down button can present users with a list of options. To create this style of button, specify the BTNS_DROPDOWN style (also called TBSTYLE_DROPDOWN for compatibility with previous versions of the common controls). To show a drop-down button with an arrow, you must also set the TBSTYLE_EX_DRAWDDARROWS toolbar style by sending a TB_SETEXTENDEDSTYLE message.
How to Customize Toolbars
Most Windows-based applications use toolbar controls to provide users with convenient access to the program functionality. However, static toolbars have some shortcomings such as too little space to effectively display all the available tools. The solution to this problem is to make your application's toolbars user-customizable. Then, users can choose to display only the tools they need, and they can organize them in a way that suits their personal workstyle.
How to Embed Nonbutton Controls in Toolbars
Toolbars support only buttons; therefore, if your application requires a different kind of control, you must create a child window. The following illustration shows a toolbar with an embedded edit control.
How to Use Hot-tracking with Toolbars
When a mouse pointer hovers over an item, the item becomes hot. If hot-tracking is enabled, the hot item is highlighted. A toolbar that is created with the TBSTYLE_FLAT style, or one that uses Visual Styles, supports hot-tracking by default.
How to Create an Internet Explorer-style Toolbar
One of the key user interface features of Windows Internet Explorer is the toolbar. It not only gives users access to a wide array of features, it also allows users to customize its layout according to their personal preferences.
How to Create an Internet Explorer-style Menu Bar
At first glance, the menu bar in Microsoft Internet Explorer 5 and later looks similar to a standard menu. However, it looks quite different when you begin using it.