方法一:
本例只讲关于响应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.xright && point.x>lpRect->left && point.ybottom && point.y>lpRect->top)
{
POINTS points;
::PostMessage(m_Static.m_hWnd,WM_MOUSEMOVE,NULL,(LPARAM)&points);
}
CDialog::OnMouseMove(nFlags, point);
}
方法二:
设置static控件的属性为notify
BEGIN_MESSAGE_MAP(CEAIJoyControl, CStatic)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
static控件就可以获取消息了
void CEAIJoyControl::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();
}
void CEAIJoyControl::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ic::OnLButtonDown(nFlags, point);
}