Adding a drop arrow to a toolbar button

If you are interested in more articles written by Kirk Stowell, you can click here to visit his home page.

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 method:


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));
	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;

	// Switch on button command id's.
	switch (pnmtb->iItem)
		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);

Download demo project - (28 KB)

Last updated December 21, 1998


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date