Click here to Skip to main content
13,554,862 members
Click here to Skip to main content
Add your own
alternative version


67 bookmarked
Posted 15 Dec 1999

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 Technologies, LLC
    United States United States
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    QuestionDropdown arrow on the bottom of the button Pin
    Bruno Scopigno28-Mar-12 5:04
    memberBruno Scopigno28-Mar-12 5:04 
    QuestionImplementing windows explorer 'views' type of menu Pin
    SharanyaMahi5-Dec-11 20:20
    memberSharanyaMahi5-Dec-11 20:20 
    Generaldropdown toolbar instead of menu Pin
    mimosa22-Jun-10 11:21
    membermimosa22-Jun-10 11:21 
    QuestionHow do I add menu item function and update function for multiple and dynamic menu items Pin
    akira3226-Oct-08 23:17
    memberakira3226-Oct-08 23:17 
    GeneralI used the vs2008 to compile the demo source code Pin
    akira3226-Oct-08 16:03
    memberakira3226-Oct-08 16:03 
    AnswerRe: I used the vs2008 to compile the demo source code Pin
    akira3226-Oct-08 17:21
    memberakira3226-Oct-08 17:21 
    GeneralBUG: CToolBar, drop-down, XP theme, and Internet Explorer Pin
    Damir Valiulin3-May-06 19:47
    memberDamir Valiulin3-May-06 19:47 
    GeneralMoving Arrow to Left of button Pin
    Hamid Reza Mohammadi2-Dec-05 5:12
    memberHamid Reza Mohammadi2-Dec-05 5:12 
    Questionboth arrows and not? Pin
    noaa28-Jul-05 14:04
    sussnoaa28-Jul-05 14:04 
    Generalreplacing button icons Pin
    prrem24-Feb-05 2:52
    memberprrem24-Feb-05 2:52 
    GeneralDrop Down Button in Internet Explorer Standard Toolbar Pin
    Atif Goheer10-Jan-04 9:26
    memberAtif Goheer10-Jan-04 9:26 
    GeneralRe: Drop Down Button in Internet Explorer Standard Toolbar Pin
    Bill SerGio, The Infomercial King4-Aug-04 4:29
    memberBill SerGio, The Infomercial King4-Aug-04 4:29 
    GeneralRe: Drop Down Button in Internet Explorer Standard Toolbar Pin
    Alexey Petuschak10-Sep-05 4:18
    memberAlexey Petuschak10-Sep-05 4:18 
    GeneralCannot click arrow Pin
    pinguin75126-Jul-03 20:01
    memberpinguin75126-Jul-03 20:01 
    GeneralRe: Cannot click arrow Pin
    Tux9-Feb-04 15:26
    memberTux9-Feb-04 15:26 
    GeneralRe: Cannot click arrow Pin
    rlaley18-Jan-05 22:34
    memberrlaley18-Jan-05 22:34 
    GeneralRe: Cannot click arrow Pin
    Rummey13-Mar-05 7:04
    sussRummey13-Mar-05 7:04 
    GeneralRe: Cannot click arrow Pin
    Kirk Stowell14-Mar-05 4:21
    memberKirk Stowell14-Mar-05 4:21 
    GeneralRe: Cannot click arrow Pin
    Rummey14-Mar-05 5:35
    memberRummey14-Mar-05 5:35 
    First, thank you so much for helping!

    Yes, I do have the ON_NOTIFY in the message map.

    I should meantion that I have this toolbar in a COM dll for an IE toolbar.

    I can make buttons to do all kinds of cool stuff, like make XMLHttpRequests, and change the current page of the browser. However, I can not get any actions assigned to the drop down button.

    GeneralRe: Cannot click arrow Pin
    Kirk Stowell14-Mar-05 10:21
    memberKirk Stowell14-Mar-05 10:21 
    GeneralRe: Cannot click arrow Pin
    Rummey14-Mar-05 10:55
    memberRummey14-Mar-05 10:55 
    GeneralRe: Cannot click arrow Pin
    Kirk Stowell15-Mar-05 4:29
    memberKirk Stowell15-Mar-05 4:29 
    GeneralRe: Cannot click arrow Pin
    Rummey15-Mar-05 4:53
    memberRummey15-Mar-05 4:53 
    GeneralRe: Cannot click arrow Pin
    Kirk Stowell15-Mar-05 5:06
    memberKirk Stowell15-Mar-05 5:06 
    GeneralRe: Cannot click arrow Pin
    CodeHead2-Sep-05 8:50
    memberCodeHead2-Sep-05 8:50 

    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.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web03 | 2.8.180515.1 | Last Updated 16 Dec 1999
    Article Copyright 1999 by Kirk Stowell
    Everything else Copyright © CodeProject, 1999-2018
    Layout: fixed | fluid