IMPLEMENT_DYNAMIC(CExStatic, CStatic)
CExStatic::CExStatic()
{
}
CExStatic::~CExStatic()
{
}
BEGIN_MESSAGE_MAP(CExStatic, CStatic)
ON_WM_MOUSEMOVE()
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
END_MESSAGE_MAP()
// CExStatic 消息处理程序
void CExStatic::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
TRACKMOUSEEVENT tme = {0};
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_HOVER|TME_LEAVE;
tme.dwHoverTime = HOVER_DEFAULT;
tme.hwndTrack = this->m_hWnd;
if (TrackMouseEvent(&tme)){}
CStatic::OnMouseMove(nFlags, point);
}
LRESULT CExStatic::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
TRACE(_T("Leave===================\n"));
return 0;
}
LRESULT CExStatic::OnMouseHover(WPARAM wParam, LPARAM lParam)
{
TRACE(_T("Hover===================\n"));
return 0;
}
void CExStatic::PreSubclassWindow()
{
// TODO: 在此添加专用代码和/或调用基类
ModifyStyle(0, SS_NOTIFY);
CStatic::PreSubclassWindow();
}
MFC OnMouseHover ON_WM_MOUSEMOVE
最新推荐文章于 2023-07-13 10:48:10 发布
本文介绍了一个自定义静态控件CExStatic的实现,该控件扩展了标准静态控件的功能,实现了鼠标悬停和离开的消息响应。通过覆写OnMouseMove、OnMouseLeave及OnMouseHover等方法,CExStatic能够跟踪鼠标状态变化,并记录鼠标悬停和离开事件。
摘要由CSDN通过智能技术生成