如何在ActiveX控件中显示Tooltip?

zhujianping_es 2007-06-05 04:58:19
ActiveX中PreTranslateMessage(...)没有调用,我处理WM_MOUSEMOVE 和WM_TIME,
此种方法在Dialog-Based程序中是没有问题的,但到了ActiveX控件中还是显示
不出来

int CCtrlBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;

EnableToolTips(TRUE);
m_TooltipCtrl.Create(this);
m_TooltipCtrl.Activate(TRUE);

CRect rect(0,0,100,100);
m_btnPlay.Create(_T("Play"),
WS_VISIBLE |WS_CHILD | BS_OWNERDRAW,
CRect(0,0,1,1),
this,
ID_BUTTON_PLAY);
m_btnPlay.LoadBitmap(IDB_PLAY,3);
m_TooltipCtrl.AddTool(&m_btnPlay,LPSTR_TEXTCALLBACK);
。。。。。。。。。
}

void CCtrlBar::OnMouseMove(UINT nFlags, CPoint point)
{
if (!m_bTimerSet)
{
SetTimer(1, 1, NULL);
m_bTimerSet = TRUE;
}

ClientToScreen(&point);

MSG msg;
msg.hwnd =m_hWnd;
msg.message= WM_MOUSEMOVE;
msg.pt=point;
msg.lParam=MAKELPARAM(point.x,point.y);
msg.wParam=nFlags;
m_TooltipCtrl.RelayEvent(&msg);
}

void CMediaCtrlBar::OnTimer(UINT nIDEvent)
{
if (nIDEvent == 1)
{
ASSERT(m_bTimerSet);

CPoint point;
GetCursorPos(&point);

CRect rc;
GetWindowRect(&rc);

if(!PtInRect(&rc,point))
{
KillTimer(1);
m_bTimerSet = FALSE;
}
else
{
MSG msg;
msg.hwnd =m_hWnd;
msg.message= WM_MOUSEMOVE;
msg.pt =point;
msg.lParam=MAKELPARAM(point.x,point.y);

m_TooltipCtrl.RelayEvent(&msg);
}
}

CWnd::OnTimer(nIDEvent);
}
...全文
1004 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
laowang2 2008-11-25
  • 打赏
  • 举报
回复
upup
蒋晟 2007-06-06
  • 打赏
  • 举报
回复
support.microsoft.com/kb/201540
support.microsoft.com/support/kb/articles/q141/8/71.asp
greenabc 2007-06-06
  • 打赏
  • 举报
回复
***.h中(要使用 Tooltip 的窗口中)
CToolTipCtrl m_tooltip;
***.cpp中


BOOL C***::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class

if(m_tooltip.m_hWnd!=NULL)
m_tooltip.RelayEvent(pMsg);
}


int C***::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here

m_tooltip.Create(this,TTS_ALWAYSTIP);
m_tooltip.AddTool(this);
m_tooltip.SetDelayTime(600); //Tooltip 显示的时间。
m_tooltip.UpdateTipText("要显示的文字",this);

return 0;
}

在父窗口中设置某个子窗口显示 Tooltip 类似。也可以。
YangAnShun 2007-06-05
  • 打赏
  • 举报
回复
创建工程的时候你继承其它控件没?
有的话,好象收不到消息
zhujianping_es 2007-06-05
  • 打赏
  • 举报
回复
不就是调用 CTooltipCtrl.RelayEvent么?
我现在在WM_MOUSEMOVE中手工调用了RelayEvent可是为什么还是不行?

不知道TooltipCtrl底层是怎么工作的?
wildmen 2007-06-05
  • 打赏
  • 举报
回复
这个功能以前实现过。不管是自己封装了一个处理消息的class。
zhujianping_es 2007-06-05
  • 打赏
  • 举报
回复
为什么没采用PreTranslateMessage可以参考:
The TAB key, arrow keys, and accelerator keys do not work as expected when an ActiveX control is the parent window of a modeless dialog box or of a propertysheet window

http://support.microsoft.com/kb/187988/en-us
zhujianping_es 2007-06-05
  • 打赏
  • 举报
回复
窗口关系是这样的:
ATL ActiveX Control(COleControl)
|----MainDialog(CDialog)
|----MediaCtrlBar(CWnd)

MediaCtrlBar里创建了一些Button类型的子窗口,我现在希望实现MediaCtrlBar中
的这些Button子窗口的Tooltip

zhujianping_es 2007-06-05
  • 打赏
  • 举报
回复
调用了,我用TRACE可以打印出来
aa3000 2007-06-05
  • 打赏
  • 举报
回复
确定已经在 ActiveX 中调用了 OnMouseMove 吗?
zhujianping_es 2007-06-05
  • 打赏
  • 举报
回复
好像也不是m_btnPlay.Create中指定的CRect(0,0,1,1)的问题,
我在CMediaCtrlBar::OnSize(UINT nType, int cx, int cy) 中做了如下的处理还是没有任何效果

CToolInfo ToolInfo;
m_TooltipCtrl.GetToolInfo(ToolInfo,&m_btnPlay);
ToolInfo.rect=temp;
m_TooltipCtrl.SetToolInfo(&ToolInfo);
zhujianping_es 2007-06-05
  • 打赏
  • 举报
回复
在OnTimer中,
CRect rectPlay;
m_btnPlay.GetWindowRect(&rectPlay);
PtInRect(rectPlay,point)测试,鼠标在Play按钮内.

但为什么Tooltip没有显示呢?

15,979

社区成员

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

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