Some people in the forum have asked questions like: How to implement a button with a drop-down arrow in the C++/MFC program similar to IE toolbar, as shown in figure
Figure A button with a drop-down arrow in the IE toolbar
This article will show you how to do this, but it's simple:
1, a new MFC/SDI project, all the way to take the default settings.
2, find the CMainFrame::OnCreate () frame window creation function in the Mainframe.cpp file. Add the following line of code at the end:
DWORD dwExStyle = TBSTYLE_EX_DRAWDDARROWS;
m_wndToolBar.GetToolBarCtrl().SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)dwExStyle);
The two lines of code are used to enable the toolbar to handle the Drop-down arrows, and then use the SetButtonStyle () method to add a Drop-down arrow button to the selected place, and in the example program, the Drop-down arrow button is added to the File Open menu:
DWORD dwStyle = m_wndToolBar.GetButtonStyle(m_wndToolBar.CommandToIndex(ID_FILE_OPEN));
dwStyle |= TBSTYLE_DROPDOWN;
m_wndToolBar.SetButtonStyle(m_wndToolBar.CommandToIndex(ID_FILE_OPEN), dwStyle);
Once you've added the line, compile the program, and then run the program, and you'll see the drop-down arrow. But it's not working at this point.
3, the next thing to do is to add the Drop-down Arrow message processing code and the program to use the menu resources. Now assume that you have created the menu resource and assume that the resource ID for this menu is idr_menu1. As shown in Figure II.
Figure II The newly created menu resource idr_menu1
A TBN_DROPDOWN message map that adds a drop-down arrow to the message map of the CMainFrame class:
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
...
ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnToolbarDropDown)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
4, in the MainFrame.h header file to add a message processing function declaration:
//{{AFX_MSG(CMainFrame)
...
afx_msg void OnToolbarDropDown(NMTOOLBAR* pnmh, LRESULT* plRes);
//}}AFX_MSG