全部博文(56)
分类: C/C++
2011-01-04 17:01:02
1. 设置CToolBarCtrl对象的扩展样式为TBSTYLE_EX_DRAWDDARROWS:
|
2. 将工具条按钮的样式设置为TBSTYLE_DROPDOWN:
- TBBUTTONINFO tbi;
- tbi.dwMask= TBIF_STYLE;
- tbi.cbSize= sizeof(TBBUTTONINFO);
- m_wndToolBar.GetToolBarCtrl().GetButtonInfo(ID_EDIT_CUT, &tbi);
- tbi.fsStyle |= TBSTYLE_DROPDOWN;
- m_wndToolBar.GetToolBarCtrl().SetButtonInfo(ID_EDIT_CUT, &tbi);
- DWORD dwStyle = m_wndToolBar.GetButtonStyle(
- m_wndToolBar.CommandToIndex(ID_FILE_OPEN));
- dwStyle |= TBSTYLE_DROPDOWN;
- m_wndToolBar.SetButtonStyle(m_wndToolBar.CommandToIndex(ID_FILE_OPEN), dwStyle);
3. 在父窗口中响应WM_NOTIFY消息,检查TBN_DROPDOWN通知:
- #define lpnm ((LPNMHDR)lParam)
- #define lpnmTB ((LPNMTOOLBAR)lParam)
- switch(lpnm->code)
- {
- case TBN_DROPDOWN:
- //drop down button was hit
- //handle appropriately
- . . .
- return FALSE; //indicates the TBN_DROPDOWN
- //notification was handled.
- }
【参考资料】:MSDN - Using Drop-Down Buttons in a Toolbar Control4. 显示菜单:
- CMenu menu;
- VERIFY(menu.LoadMenu(IDR_MENU1));
- CMenu* pPopup = menu.GetSubMenu(0);
- ASSERT(pPopup != NULL);
- pPopup->TrackPopupMenu(TPM_RIGHTALIGN |
- TPM_RIGHTBUTTON, x, y, this);