1 / 18
文档名称:

第07章鼠标、键盘、计时器.ppt

格式:ppt   大小:377KB   页数:18页
下载后只包含 1 个 PPT 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

第07章鼠标、键盘、计时器.ppt

上传人:mh900965 2018/2/21 文件大小:377 KB

下载得到文件列表

第07章鼠标、键盘、计时器.ppt

相关文档

文档介绍

文档介绍:第7章鼠标、键盘、计时器
本章主要内容
鼠标的客户区消息和非客户区消息的处理
鼠标消息的捕获
处理键盘消息
  处理鼠标消息
根据产生鼠标消息时鼠标光标所处的位置,鼠标消息分为两类:
客户区鼠标消息
非客户区鼠标消息
  常用鼠标消息
  常用鼠标消息
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
MFC中,鼠标消息响应函数的原型一般为:
afx_msg void OnLButtonDown(
UINT nFlags, CPoint point );
掩码
产生鼠标消息时光标在窗口客户区的位置
 常用鼠标消息
 常用鼠标消息
 常用鼠标消息
afx_msg BOOL OnSetCursor( CWnd* pWnd,
UINT nHitTest, UINT message);
if( m_nMouseState == mapPan )
{
if( SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_HMOVE)) ) return TRUE ;
}
else if( m_nMouseState == mapZoomin )
{
if( SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_ZOOMIN)) )
return TRUE ;
}
else
{
if( ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)) )
return TRUE ;
}
如果鼠标处在应用程序窗口之外,还希望可以接受鼠标消息的话,则必须调用捕获鼠标消息函数:
CWnd* SetCapture();
完成了所应该做的工作之后,应用程序应该及时释放鼠标:
BOOL ReleaseCapture();
  捕获鼠标消息
  捕获鼠标消息举例
SetCapture();
//回到顺序编程
for (;;)
{ MSG msg;
VERIFY(::GetMessage(&msg, NULL, 0, 0));
case WM_LBUTTONDOWN: { }break;
case WM_MOUSEMOVE: { }break;
case WM_LBUTTONUP: { }break;
default: DispatchMessage(&msg); break;
}
ReleaseCapture();