description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: Using Drop-Down Buttons in a Toolbar Control |
Using Drop-Down Buttons in a Toolbar Control |
11/04/2016 |
|
|
b859f758-d2f6-40d9-9c26-0ff61993b9b2 |
In addition to standard push buttons, a toolbar can also have drop-down buttons. A drop-down button is usually indicated by the presence of an attached down arrow.
Note
The attached down arrow will appear only if the TBSTYLE_EX_DRAWDDARROWS extended style has been set.
When the user clicks on this arrow (or the button itself, if no arrow is present), a TBN_DROPDOWN notification message is sent to the parent of the toolbar control. You can then handle this notification and display a pop-up menu; similar to the behavior of Internet Explorer.
The following procedure illustrates how to implement a drop-down toolbar button with a pop-up menu:
-
Once your
CToolBarCtrl
object has been created, set the TBSTYLE_EX_DRAWDDARROWS style, using the following code:[!code-cppNVC_MFCControlLadenDialog#36]
-
Set the TBSTYLE_DROPDOWN style for any new (InsertButton or AddButtons) or existing (SetButtonInfo) buttons that will be drop-down buttons. The following example demonstrates modifying an existing button in a
CToolBarCtrl
object:[!code-cppNVC_MFCControlLadenDialog#37]
-
Add a TBN_DROPDOWN handler to the parent class of the toolbar object.
[!code-cppNVC_MFCControlLadenDialog#38]
-
In the new handler, display the appropriate popup menu. The following code demonstrates one method:
[!code-cppNVC_MFCControlLadenDialog#39]