怎样把一个popupmenu加入到一个浮动的toolbar中去啊?

doudourabbit 2002-05-17 11:34:45
如题
...全文
50 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
doudourabbit 2002-05-22
  • 打赏
  • 举报
回复
pcman1990意思也是我想的,但是我需要例子。。。。
蒋晟 2002-05-17
  • 打赏
  • 举报
回复
To implement a drop-down button

Once your CToolBarCtrl object has been created, set the TBSTYLE_EX_DRAWDDARROWS style, using the following code:
m_wndToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);

Set the TBSTYLE_DROPDOWN style for any new (InsertButton orAddButtons) or existing (SetButtonInfo) buttons that will be drop-down buttons. The following example demonstrates modifying an existing button in a CToolBarCtrl object:
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);

Add a WM_NOTIFY handler to the parent class of the toolbar object.


In the new handler, check for the TBN_DROPDOWN notification, using the following code:
#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.
}

If the TBN_DROPDOWN notification has been sent, display the appropriate popup menu. The following code demonstrates one method:
CMenu menu;
VERIFY(menu.LoadMenu(IDR_MENU1));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
pPopup->TrackPopupMenu(TPM_RIGHTALIGN |
TPM_RIGHTBUTTON, x, y, this);

BUG: Resizing CToolbar with Dropdown Arrow Buttons Freezes Apps
Q190501


--------------------------------------------------------------------------------
The information in this article applies to:

The Microsoft Foundation Classes (MFC), included with:
Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0
Microsoft Visual C++, 32-bit Professional Edition, version 6.0
Microsoft Visual C++, 32-bit Learning Edition, version 6.0

--------------------------------------------------------------------------------


pcman1990 2002-05-17
  • 打赏
  • 举报
回复
是不是可以继承CToolBar类,然后在该类中自己处理右键点击的消息.
Hover 2002-05-17
  • 打赏
  • 举报
回复
......
doudourabbit 2002-05-17
  • 打赏
  • 举报
回复
这个我知,问题是我要用户只在那个toolbar范围内右键单击才显示这个菜单,除此以外不显示.我想添加CToolBar的鼠标单击事件,但是怎么添加呢??
akinge 2002-05-17
  • 打赏
  • 举报
回复
void CMyView::OnRButtonDown(UINT nFlags, CPoint point)
{
CView::OnRButtonDown(nFlags, point);

CMenu* menu_bar = AfxGetMainWnd()->GetMenu();
CMenu* file_menu = menu_bar->GetSubMenu(0);
ASSERT(file_menu);

file_menu->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x,
point.y, this);
}

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧