MFC2.鼠标消息

 
VC++鼠标消息知识
以下代码在VC++6.0编译通过
1.鼠标的9个消息
1.WM_LBUTTONDBLCLK //鼠标左键双击
2.WM_LBUTTONDOWN    //鼠标左键按下
3.WM_LBUTTONUP          //鼠标左键放开
4.WM_MBUTTONDOWN //鼠标中键按下
5.WM_MBUTTONUP                 //鼠标中键放开
6.WM_RBUTTONDBLCLK         //鼠标右键双击
7.WM_RBUTTONDOWN    //鼠标右键按下
8.WM_RBUTTONP            //鼠标右键放开
9.WM_MOUSEMOVE                 //鼠标移动
 
 
2.code demo.
 
//此用户自己定义的函数,
//第一步是在CMouseView类中声明public: void showinfo(const char*,CPoint)
//第二步是在CMouseView类中实现,代码如下
void CMouseView::showinfo(const char* info,CPoint pt)
{//手工建立此函数代码,则它不是系统消息,则需要消息映射
        InvalidateRect( NULL, FALSE );
        UpdateWindow();
        CClientDC ct1(this);
        CString string1;
        string1.Format("x:%d Y:%d %s          ",pt.x,pt.y,info);
        ct1.TextOut(pt.x,pt.y,string1,string1.GetLength());
}
 
//以下所有鼠标的消息函数请用类向导建立,它会自动建立消息映射的声明和定义
//类向导自动建立消息映射的声明
        //{{AFX_MSG(CMouseView)
        afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
        afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
        afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
        afx_msg void OnMouseMove(UINT nFlags, CPoint point);
        afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
        afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
        afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
 
//类向导自动建立消息映射的定义
BEGIN_MESSAGE_MAP(CMouseView, CView)
        //{{AFX_MSG_MAP(CMouseView)
        ON_WM_LBUTTONDBLCLK()
        ON_WM_LBUTTONDOWN()
        ON_WM_LBUTTONUP()
        ON_WM_MOUSEMOVE()
        ON_WM_RBUTTONDBLCLK()
        ON_WM_RBUTTONDOWN()
        ON_WM_RBUTTONUP()
        //}}AFX_MSG_MAP
...
END_MESSAGE_MAP()
 
 
void CMouseView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
        showinfo("OnLButtonDblClk",point);//手工添加代码     
        CView::OnLButtonDblClk(nFlags, point);
}
 
void CMouseView::OnLButtonDown(UINT nFlags, CPoint point)
{
        showinfo("OnLButtonDown",point);//手工添加代码
        CView::OnLButtonDown(nFlags, point);
}
 
void CMouseView::OnLButtonUp(UINT nFlags, CPoint point)
{
        showinfo("OnLButtonUp",point);//手工添加代码
        CView::OnLButtonUp(nFlags, point);
}
 
void CMouseView::OnMouseMove(UINT nFlags, CPoint point)
{
        CClientDC ct1(this);//手工添加代码
        CString string1;//手工添加代码
        string1.Format("x:%d Y:%d",point.x,point.y,string1);//手工添加代码
        ct1.TextOut(10,10,string1,string1.GetLength());//手工添加代码
        CView::OnMouseMove(nFlags, point);
}
 
void CMouseView::OnRButtonDblClk(UINT nFlags, CPoint point)
{
        showinfo("OnRButtonDblClk",point);//手工添加代码
        CView::OnRButtonDblClk(nFlags, point);
}
 
void CMouseView::OnRButtonDown(UINT nFlags, CPoint point)
{
 
        showinfo("OnRButtonDown",point);//手工添加代码
        CView::OnRButtonDown(nFlags, point);
}
 
void CMouseView::OnRButtonUp(UINT nFlags, CPoint point)
{
        showinfo("OnRButtonUp",point);//手工添加代码
        CView::OnRButtonUp(nFlags, point);
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值