我现在知道 一个窗口的句柄, 有没有方法在他的标题栏上显示一个 tooltip?CToolTipCtrl这个类感觉都是和控件相结合的,各位帮忙啊
解决方案 »
- 函数参数可用来定义变量吗?
- 关于Unicode定义
- 透明问题:
- 在线程中调用CDocument的UpdateAllViews,出现异常!
- Unhandled exception in test.exe: 0xC0000005:Access Violation
- bcgcontrolbar 5.90谁有?
- 使用TADOConnection的dll需要delphi环境支持吗?
- 关于Dialog的大小问题!(在线等待,马上给分)
- 如何通过tab控件页面上面的按钮关闭主窗口
- 请教高手:如何调试动态链接库(DLL),是否有相应的模拟环境用来调试!!
- 对话框上创建工具栏
- 新手急 问:cedit编辑框问题, 谢谢
在PreTranslateMessage中GetCursorPos取鼠标位置,如果在标题栏就 m_tt.RelayEvent(pMsg);
http://blog.csdn.net/leon_founder/archive/2007/07/24/1705200.aspx
其实控件和对话框一样都是一个窗体
m_tt.Activate(TRUE);
m_tt.AddTool( this,"Tip Text!");
m_tt.SetDelayTime(TTDT_INITIAL,1 );
m_tt.SetDelayTime(TTDT_AUTOPOP,1000);BOOL C***Dlg::PreTranslateMessage(MSG* pMsg)
{
CRect rtWnd,rtTitle;
GetWindowRect(&rtWnd); //取得窗口的屏幕坐标 CPoint offpt;
offpt.x = rtWnd.left+GetSystemMetrics( SM_CXFRAME );
offpt.y = rtWnd.top +GetSystemMetrics( SM_CYFRAME ); rtTitle.left = GetSystemMetrics( SM_CXFRAME );
rtTitle.top = GetSystemMetrics( SM_CYFRAME );
rtTitle.right = rtWnd.right - rtWnd.left - GetSystemMetrics(SM_CXFRAME);
rtTitle.bottom = rtTitle.top + GetSystemMetrics(SM_CYSIZE);
rtTitle.OffsetRect( offpt ); //取得标题栏的屏幕坐标
CPoint pt; ::GetCursorPos( &pt ); //取得鼠标的屏幕坐标 if( pMsg->message == WM_NCMOUSEMOVE && rtTitle.PtInRect( pt ) )
{
this->SetFocus();
MSG ppMsg;
ppMsg.hwnd = this->m_hWnd;
ppMsg.lParam = pMsg->lParam;
ppMsg.message = pMsg->message;
ppMsg.time = pMsg->time;
ppMsg.wParam = pMsg->wParam;
ppMsg.pt = pt;
m_tt.RelayEvent(&ppMsg); }else if( pMsg->message == 0x02A2 ){ MSG ppMsg;
ppMsg.hwnd = this->m_hWnd;
ppMsg.lParam = pMsg->lParam;
ppMsg.message = pMsg->message;
ppMsg.time = pMsg->time;
ppMsg.wParam = pMsg->wParam;
ppMsg.pt.x = 10000;
ppMsg.pt.y = 10000;
m_tt.RelayEvent(&ppMsg);
}
return CDialog::PreTranslateMessage(pMsg);
}虽然上面的代码未必满足楼主的要求,但是至少可以显示提示。楼主要在鼠标当前位置显示Tip有一个最大的问题,上面的代码也是这样的,那就是Dialog本身的区域显示。因为标题栏不属于客户区,所以当传了
this指针以后,tip显示的范围就固定了,只能在标题栏下面(包括菜单、工具栏,如果有的话)。想直接连标题栏上都显示tip不太可能。如果楼主十分想要达到完美的效果,那恐怕只能放弃使用CToolTipCtrl,而是按照CToolTipCtrl的样子自己去写一个类。
楼主可以参考:http://www.codeproject.com/KB/miscctrl/pptooltip.aspx
我说的参考是参考里面消息处理和定时机制,处理比较复杂。