Click here to Skip to main content
12,557,148 members (30,816 online)
Click here to Skip to main content
Add your own
alternative version


67 bookmarked

Adding a drop arrow to a toolbar button

, 15 Dec 1999
Rate this:
Please Sign up or sign in to vote.
Demonstrates how to use the new toolbar styles to add dropdown arrows to toolbar buttons
  • Download demo project - 28 Kb
  • Sample Image - toolbar_droparrow.gif

    <!-- Article Starts -->

    If you wanted to add a drop menu like the ones seen in internet explorer, it is pretty straight forward. This approach for will work for both Visual C++ 5 and 6, however you may want to read up on the enhancements to the toolbar class for VC 6.0.

    First off, after your toolbar has been created in CMainFrame::OnCreate(), you will need to make a call to the following

    m_wndToolBar.GetToolBarCtrl().SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)dwExStyle);

    This will enable your toolbar to handle drop arrows. The next thing you will need to do, is to actually add the drop arrow to your desired button. This will be done via the SetButtonStyle() method:

    DWORD dwStyle = m_wndToolBar.GetButtonStyle(m_wndToolBar.CommandToIndex(ID_FILE_OPEN));
    dwStyle |= TBSTYLE_DROPDOWN;
    m_wndToolBar.SetButtonStyle(m_wndToolBar.CommandToIndex(ID_FILE_OPEN), dwStyle);

    Now, you will need to add a message handler for the drop arrow, as well a menu to the application resources. Assuming you already know how to create a menu, ( if not, click on the resource tab, select the resource name ie: MyApp Resources, then right click. Select insert, then select Menu, then press the New button ) and assuming that the resource id for our menu is IDR_MENU1, add the following code to CMainFrame's message map:


    Add the following method to CMainFrame's .cpp file:

    void CMainFrame::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)
    	CWnd *pWnd;
    	UINT nID;
    	// Switch on button command id's.
    	switch (pnmtb->iItem)
    	case ID_FILE_OPEN:
    		pWnd = &m_wndToolBar;
    		nID  = IDR_MENU1;
    	// load and display popup menu
    	CMenu menu;
    	CMenu* pPopup = menu.GetSubMenu(0);
    	CRect rc;
    	pWnd->SendMessage(TB_GETRECT, pnmtb->iItem, (LPARAM)&rc);
    		rc.left, rc.bottom, this, &rc);

    Then add the following to CMainFrame's .h file:

    afx_msg void OnToolbarDropDown(NMTOOLBAR* pnmh, LRESULT* plRes);


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    Kirk Stowell
    CEO Codejock Software
    United States United States
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    AnswerRe: Cannot click arrow Pin
    Kirk Stowell2-Sep-05 10:49
    memberKirk Stowell2-Sep-05 10:49 
    GeneralRe: Cannot click arrow Pin
    CodeHead6-Sep-05 2:52
    memberCodeHead6-Sep-05 2:52 
    QuestionHow can I do it in a docking toolbar? Pin
    PaulaPaziani25-Jul-03 6:42
    memberPaulaPaziani25-Jul-03 6:42 
    QuestionHow to do it in C#? Pin
    Carl Mercier23-Feb-03 11:18
    memberCarl Mercier23-Feb-03 11:18 
    GeneralGood Job Pin
    Old Timer8-Jan-03 2:57
    memberOld Timer8-Jan-03 2:57 
    GeneralVC++.NET Problem Pin
    Anonymous12-Aug-02 13:28
    sussAnonymous12-Aug-02 13:28 
    GeneralRe: VC++.NET Problem Pin
    Kirk Stowell13-Aug-02 4:44
    memberKirk Stowell13-Aug-02 4:44 
    GeneralRe: VC++.NET Problem Pin
    haoshenghan1-May-04 0:05
    memberhaoshenghan1-May-04 0:05 
    GeneralRe: VC++.NET Problem Pin
    Bausch23-May-06 23:17
    memberBausch23-May-06 23:17 
    GeneralRe: VC++.NET Problem Pin
    Ani4-Jul-06 18:51
    memberAni4-Jul-06 18:51 
    GeneralRe: VC++.NET Problem Pin
    karthikeyan nithiyanandavelu1-Jan-07 19:49
    memberkarthikeyan nithiyanandavelu1-Jan-07 19:49 
    GeneralRe: VC++.NET Problem Pin
    dangero19-Jun-08 17:04
    memberdangero19-Jun-08 17:04 
    GeneralAbsolutely brilliant Pin
    DanPetitt9-Aug-02 10:08
    memberDanPetitt9-Aug-02 10:08 
    GeneralRedo/Undo Dropdown Window Pin
    Anonymous20-Jun-02 5:13
    memberAnonymous20-Jun-02 5:13 
    GeneralA very little addition Pin
    Morozov Alexey19-Feb-02 13:56
    memberMorozov Alexey19-Feb-02 13:56 
    GeneralText Menus Pin
    swinefeaster28-Oct-01 12:29
    memberswinefeaster28-Oct-01 12:29 
    GeneralDoing this in a CDialog window Pin
    Jeremy Davis20-Mar-00 5:36
    sussJeremy Davis20-Mar-00 5:36 
    GeneralTrouble with doing this in a CDialog Pin
    Jeremy Davis21-Feb-00 3:29
    sussJeremy Davis21-Feb-00 3:29 
    GeneralBug in VC6 MFC with dropdown arrows in toolbars Pin
    Martin Speiser21-Jan-00 3:55
    sussMartin Speiser21-Jan-00 3:55 
    GeneralBug in VC6 MFC with dropdown arrows in toolbars Pin
    Martin Speiser21-Jan-00 3:55
    sussMartin Speiser21-Jan-00 3:55 
    GeneralBug in VC6 MFC with dropdown arrows in toolbars Pin
    Martin Speiser21-Jan-00 3:55
    sussMartin Speiser21-Jan-00 3:55 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Terms of Use | Mobile
    Web02 | 2.8.161026.1 | Last Updated 16 Dec 1999
    Article Copyright 1999 by Kirk Stowell
    Everything else Copyright © CodeProject, 1999-2016
    Layout: fixed | fluid