关于MFC中ToolBar鼠标悬停提示的问题

DefineLove 2010-05-11 02:13:44
程序结构是这样:主窗体CMainFrame、菜单(为什么用SPY++抓的时候显示的是ToolBar?),我现在要在菜单下面加一行ToolBar,我用的是CTrueColorToolBar这个类,图片可以出现,为了实现悬停提示,我在CTrueColorToolBar中 .h中声明:CToolTipCtrl tip;和virtual BOOL CDemo2View::PreTranslateMessage(MSG* pMsg);
.cpp中实现:
BOOL CDemo2View::PreTranslateMessage(MSG* pMsg)
{
if(tip.m_hWnd)
tip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}

然后在CMainFrame中创建工具条时
if (!m_toolbarMain.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT,
WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP
| CBRS_TOOLTIPS) ||
!m_toolbarMain.LoadToolBar(IDR_TOOLBAR_MAINBAR))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_toolbarMain.SetHeight(30);
m_toolbarMain.LoadTrueColorToolBar(24, IDB_BITMAP_NORMAL, IDB_BITMAP_HOT, IDB_BITMAP_HOT);

下面 m_toolbarMain.tip.Create(&m_toolbarMain);
m_toolbarMain.tip.Activate(TRUE);
EnableToolTips(TRUE);
CRect rect1(0,0,50,50); //设置提示区域1
m_toolbarMain.tip.AddTool(this,"tooltip",&rect1,1); //添加提示区域1
CRect rect2(100,100,150,150); //设置提示区域2
m_toolbarMain.tip.AddTool(this,"tooltip",&rect2,1); //添加提示区域2

为什么悬停提示出不来? 还有鼠标移到ToolBar上面的菜单栏时会出现悬停提示,汗.. m_toobarMain是我在CMainFrame中声明的CTrueColorToolBar对象。 怎么解决?有没有更好的ToolBar类推荐一下,我只需要实现图片和悬停提示。谢谢,分不多..
...全文
602 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
GavrocheApple 2010-05-24
  • 打赏
  • 举报
回复
我想问你一个问题哦……我也在做MFC,也需要用到tool tip,
我的做法是:
在mainDlg里添加一个m_tip_inquire变量,是CToolTipCtrl类的,

在mainDlg.cpp的OnInitDialog 里加入:
m_tip_inquire.Create(this);
m_tip_inquire.AddTool(GetDlgItem(IDC_EDIT),_T("查询框"));

并且在mainDlg类中重载PreTranslateMessage(MSG * pMsg)
{
m_tip_inquire.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}

可是我根本实现不了功能呀……程序一运行就崩溃……我完全没有头绪……怎么办怎么办……
liyelun 2010-05-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 definelove 的回复:]
我刚才解决了.. 我用的是VC6.0 学友的头像,我喜欢.. OK 分给你 结贴!
[/Quote]
额....
那谢谢楼主,谢谢学友哥
DefineLove 2010-05-11
  • 打赏
  • 举报
回复
我刚才解决了.. 我用的是VC6.0 学友的头像,我喜欢.. OK 分给你 结贴!
liyelun 2010-05-11
  • 打赏
  • 举报
回复
CBCGPToolBar,不过要安装BCG的
当然如果是VS2008的话就不用安装了
VS2008里面对应的好像是CMFCToolBar

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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