MFC 中Static text 如何响应鼠标hover事件?
如题,本人想用静态文本实现超链接功能,当鼠标放在文本上,文本内容显示下划线。请问如何实现。知道的指导小弟一下,不胜感激...
如题,本人想用静态文本实现超链接功能,当鼠标放在文本上,文本内容显示下划线。请问如何实现。知道的指导小弟一下,不胜感激
展开
2个回答
展开全部
重耐念载CStatic类,在鼠标姿滚入入事件中添加
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE | TME_HOVER;
tme.dwHoverTime = 1;
_TrackMouseEvent(&tme);
则会接收到鼠标昌册困离开事件。
BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_MOUSEMOVE,mv)
ON_MESSAGE(WM_MOUSEHOVER,mho)
ON_MESSAGE(WM_MOUSELEAVE,ml)
ON_MESSAGE(WM_MOUSEFIRST,mf)
END_MESSAGE_MAP()
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE | TME_HOVER;
tme.dwHoverTime = 1;
_TrackMouseEvent(&tme);
则会接收到鼠标昌册困离开事件。
BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_MOUSEMOVE,mv)
ON_MESSAGE(WM_MOUSEHOVER,mho)
ON_MESSAGE(WM_MOUSELEAVE,ml)
ON_MESSAGE(WM_MOUSEFIRST,mf)
END_MESSAGE_MAP()
更多追问追答
追问
我重写了CStatic类,但是不能相应鼠标HOver和鼠标进入的消息,能相应鼠标移动的消息
追答
CMyStatic::CMyStatic(CTestMFCDlg* p):m_p(p),m_bin(false)
{
}
CMyStatic::~CMyStatic(void)
{
}
LRESULT CMyStatic::mv(WPARAM wParam,LPARAM lParam){
if(!m_bin){
m_bin=true;
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE | TME_HOVER;
tme.dwHoverTime = 1;
_TrackMouseEvent(&tme);
}
if(m_p)
m_p->PostMessage(MY_MESSAGE,0,lParam);
return 0;
}
BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_MOUSEMOVE,mv)
ON_MESSAGE(WM_MOUSEHOVER,mho)
ON_MESSAGE(WM_MOUSELEAVE,ml)
ON_MESSAGE(WM_MOUSEFIRST,mf)
END_MESSAGE_MAP()
LRESULT CMyStatic::ml(WPARAM wParam,LPARAM lParam){
m_bin=false;
if(m_p)
m_p->PostMessage(MY_MESSAGE,1,lParam);
return 0;
}
LRESULT CMyStatic::mho(WPARAM wParam,LPARAM lParam){
if(m_p)
m_p->PostMessage(MY_MESSAGE,2,lParam);
return 0;
}
LRESULT CMyStatic::mf(WPARAM wParam,LPARAM lParam){
if(m_p)
m_p->PostMessage(MY_MESSAGE,3,lParam);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询