• 全部
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • 界面
  • 进程
  • 算法
  • 硬件/系统
  • 数据库
  • VC++技术资源

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

doudourabbit 2002-05-17 11:34:45
如题
...全文
13 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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);
}
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2002-05-17 11:34
社区公告

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