如何让自定义的基于CStatic的控件响应鼠标

发布网友 发布时间:2022-04-22 08:21

我来回答

1个回答

热心网友 时间:2022-06-18 12:51

方法一:
本例只讲关于响应WM_MOUSEMOVE消息的处理,其它的消息以此类推.
可以通过在对话框的WM_MOUSEMOVE消息里检查是否鼠标移进Static控件,若是,就PostMessage()给Static控件.
void CDlgDlg::OnMouseMove(UINT nFlags, CPoint point)
{
LPRECT lpRect=new RECT;
m_Static.GetWindowRect(lpRect);
ScreenToClient(lpRect);
if(point.x<lpRect->right && point.x>lpRect->left && point.y<lpRect->bottom && point.y>lpRect->top)
{
POINTS points;
::PostMessage(m_Static.m_hWnd,WM_MOUSEMOVE,NULL,(LPARAM)&points);
}
CDialog::OnMouseMove(nFlags, point);
}
方法二:
设置static控件的属性为notify
static控件就可以获取消息了
void CXXStatic::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
DWORD dwStyle = GetStyle();
::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
CStatic::PreSubclassWindow();
}
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com
Top