VC 中使用 CToolTipCtrl 消失后不再出现的Bug。。。。
2014-03-20 16:24
344 查看
最近用WTL重写CGdipButton。从ButtonST中将CtoolTipCtrl的相关代码转过来,发现一个问题:
ToolTip可以显示,鼠标移开后再移动到button上也可以再次显示,但是按下button或者等待tootip自动消失后,tooptip就不会再显示了。。。
郁闷了几天今天偶然看到MSDN论坛的一个答复,(http://social.msdn.microsoft.com/Forums/en-US/dfea9abc-8535-4a43-918a-a78f88b77c70/tooltip-does-not-appear-after-click?forum=winforms)我又喷血了,因为在之前的代码中加两句代码就解决了。。。。
贴下相关代码
ToolTip可以显示,鼠标移开后再移动到button上也可以再次显示,但是按下button或者等待tootip自动消失后,tooptip就不会再显示了。。。
郁闷了几天今天偶然看到MSDN论坛的一个答复,(http://social.msdn.microsoft.com/Forums/en-US/dfea9abc-8535-4a43-918a-a78f88b77c70/tooltip-does-not-appear-after-click?forum=winforms)我又喷血了,因为在之前的代码中加两句代码就解决了。。。。
贴下相关代码
// GdipButton.h #pragma once class CGdipButton : public CWindowImpl<CGdipButton, CButton> { public: CGdipButton(); virtual ~CGdipButton(); void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE); protected: BEGIN_MSG_MAP_EX(CGdipButton) MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseMessage) MSG_WM_MOUSEHOVER(OnMouseHover) MSG_WM_MOUSELEAVE(OnMouseLeave) END_MSG_MAP() LRESULT OnMouseMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); void OnMouseHover(WPARAM wParam, CPoint point); void OnMouseLeave(); private: void InitToolTip(); BOOL m_bHovering; CToolTipCtrl m_toolTip; };
// GdipButton.cpp #include "stdafx.h" #include "GdipButton.h" CGdipButton::CGdipButton() { m_bHovering = FALSE; } CGdipButton::~CGdipButton() { } LRESULT CGdipButton::OnMouseMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { // track hover msg and leave msg if(WM_MOUSEMOVE == uMsg) { TRACKMOUSEEVENT tme; tme.cbSize = sizeof(TRACKMOUSEEVENT); tme.dwFlags = TME_HOVER | TME_LEAVE; tme.dwHoverTime = 20; tme.hwndTrack = m_hWnd; _TrackMouseEvent(&tme); } if(m_toolTip.IsWindow()) { m_toolTip.RelayEvent((LPMSG)m_pCurrentMsg); } bHandled = false; return 1; } void CGdipButton::OnMouseHover(WPARAM wParam, CPoint point) { if(!m_bHovering) { m_bHovering = TRUE; Invalidate(); } } void CGdipButton::OnMouseLeave() { // 就是这两句 // 要先判断下是否存在m_toolTip窗口,否则未添加toolTip的button会出错。。。 if(m_toolTip.IsWindow()) { m_toolTip.Activate(FALSE); m_toolTip.Activate(TRUE); } m_bHovering = FALSE; Invalidate(); } void CGdipButton::SetTooltipText(LPCTSTR lpszText, BOOL bActivate) { if(NULL == lpszText) { return; } InitToolTip(); if (m_toolTip.GetToolCount() == 0) { CRect rectBtn; GetClientRect(rectBtn); m_toolTip.AddTool(*this, lpszText, rectBtn, 1); } m_toolTip.UpdateTipText(lpszText, *this, 1); m_toolTip.Activate(bActivate); } void CGdipButton::InitToolTip() { if(NULL == m_toolTip.m_hWnd) { m_toolTip.Create(*this); m_toolTip.Activate(FALSE); m_toolTip.SetMaxTipWidth(400); } }
相关文章推荐
- IE6中a标签同时使用inline-block与text-indent时出现的BUG
- [bug]超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。
- ACCESS有个BUG,那就是在使用 like 搜索时如果遇到日文就会出现“内存溢出”的问题
- VC轻松解析XML文件--CMarkup使用方法(解决解析中文字符出现乱码问题)
- ArcGIS API for JavaScript使用中出现的BUG(1)
- 使用VC的Class Wizard派生父类为CRecordset类时出现的错误
- VC使用 ADO是 出现的 ERROR 3092
- VC关于使用了相关控件的程序出现:该内存不能为read的解决办法
- 使用VS 2008(带sp1)编译VC 6.0的一个工程,出现下面的编译错误
- 使用FloatingActionButton滑动消失后不再显示问题
- VC中使用STL出现的警告.
- VC中使用CFile正确的追加写中文数据到文件不出现乱码-unicode字符集
- 关于使用Hibernateni逆向工程生成model出现的BUG
- [开发工具]_[VS2010]_[vs2010的一个bug-使用stringstream时出现]
- 使用bounds出现的一个小bug解决方案
- 使用jquery 给table绑定jqgrid 出现的bug
- 正则表达式(regex)或操作符”|“使用易出现功能Bug
- 在使用v4包中的fragment时出现空指针的bug
- 在VC/VS中使用模板成员函数时,出现LNK2001错误
- [BUG]BasePopupWindow 使用时出现java.lang.ClassCastException