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

方法一:
本例只讲关于响应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);
}

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值