您的位置:首页 > 其它

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

2012-10-11 10:52 495 查看
方法一:

本例只讲关于响应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();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: