--适用于VC6
1、在CMainFrame::OnCreate修改工具栏属性:
// 下拉属性
DWORD dwExStyle = TBSTYLE_EX_DRAWDDARROWS;
m_wndToolBar.GetToolBarCtrl().SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)dwExStyle);
DWORD dwStyle = m_wndToolBar.GetButtonStyle(m_wndToolBar.CommandToIndex(ID_FILE_SAVE));
dwStyle |= TBSTYLE_DROPDOWN;
m_wndToolBar.SetButtonStyle(m_wndToolBar.CommandToIndex(ID_FILE_SAVE), dwStyle); // 对ID_FILE_SAVE工具栏按钮设置下拉属性
2、映射TBN_DROPDOWN消息:
1)MainFrm.h添加:
afx_msg void OnToolbarDropDown(NMTOOLBAR* pnmh, LRESULT* plRes);
2)消息处理添加:
ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnToolbarDropDown)
3)消息处理函数:
void CMainFrame::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)
{
// 处理下拉按钮消息
CWnd *pWnd;
UINT nID;
// Switch on button command id''s.
switch (pnmtb->iItem)
{
case ID_FILE_SAVE:
pWnd = &m_wndToolBar;
nID = IDR_MENU1; // 下拉菜单ID
break;
default:
return;
}
// load and display popup menu
CMenu menu;
menu.LoadMenu(nID);
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup);
CRect rc;
pWnd->SendMessage(TB_GETRECT, pnmtb->iItem, (LPARAM)&rc);
pWnd->ClientToScreen(&rc);
pPopup->TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL,
rc.left, rc.bottom, this, &rc);
}