如何让自定义的基于CStatic的控件响应鼠标
1个回答
展开全部
方法一:
本例只讲关于响应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();
}
本例只讲关于响应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();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询