08第八章 MFC程序设计-鼠标和键盘

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

MFC程序设计鼠标和键盘作者:李季主要内容鼠标消息分类客户区鼠标消息非客户区鼠标消息光标键盘消息鼠标消息分类客户区鼠标消息非客户区鼠标消息客户区鼠标消息消息发送条件WM_LBUTTONDOWN鼠标左键被按下WM_LBUTTONUP鼠标左键被释放WM_LBUTTONDBLCLK鼠标左键被双击WM_MBUTTONDOWN鼠标中间键被按下WM_MBUTTONUP鼠标中间键被释放WM_MBUTTONDBLCLK鼠标中间键被双击WM_RBUTTONDOWN鼠标右键被按下WM_RBUTTONUP鼠标右键被释放WM_RBUTTONDBLCLK鼠标右键被双击WM_MOUSEMOVE在窗口客户区移动了光标客户区鼠标消息当窗口的WNDCLASS包含类样式CS_DBLCLKS,在很短时间内同一鼠标键被连续单击两次时,第二次键按下消息被WM_xBUTTONDBLCLK消息取代。默认情况下,框架窗口接受双击消息。客户区鼠标消息未注册双击消息,连续单击两次产生下面消息序列:–WM_xBUTTONDOWN–WM_xBUTTONUP–WM_xBUTTONDOWN–WM_xBUTTONUP客户区鼠标消息已注册双击消息,连续单击两次产生下面消息序列:–WM_xBUTTONDOWN–WM_xBUTTONUP–WM_xBUTTONDBLCLK–WM_xBUTTONUP客户区鼠标消息参数CPointpoint–指出光标位置,客户区坐标–在WM_MOUSEMOVE消息中,指出最近的光标位置UINTnFlags–消息生成时鼠标键以及Shift键和Ctrl键的状态客户区鼠标消息掩码涵义MK_LBUTTON鼠标左键被按下MK_MBUTTON鼠标中间键被按下MK_RBUTTON鼠标右键被按下MK_CONTROLCtrl键被按下MK_SHIFTShift键被按下非客户区鼠标消息消息发送条件WM_NCLBUTTONDOWN鼠标左键被按下WM_NCLBUTTONUP鼠标左键被释放WM_NCLBUTTONDBLCLK鼠标左键被双击WM_NCMBUTTONDOWN鼠标中间键被按下WM_NCMBUTTONUP鼠标中间键被释放WM_NCMBUTTONDBLCLK鼠标中间键被双击WM_NCRBUTTONDOWN鼠标右键被按下WM_NCRBUTTONUP鼠标右键被释放WM_NCRBUTTONDBLCLK鼠标右键被双击WM_NCMOUSEMOVE在窗口非客户区移动了光标非客户区鼠标消息无论窗口是否注册CS_DBLCLKS样式,WM_NCxBUTTONDBLCLK消息都要被发送。非客户区鼠标消息参数CPointpoint–指出光标位置,屏幕坐标–在WM_MOUSEMOVE消息中,指出最近的光标位置UINTnHitTest–包含标识窗口非客户区上事件发生地点的命中测试码非客户区鼠标消息参数值相应位置HTCAPTION标题栏HTCLOSE关闭按钮HTGROWBOX还原按钮(与HTSIZE相同)HTHSCROLL窗口的水平滚动栏HTMENU菜单栏HTREDUCE最小化按钮HTSIZE还原按钮(与HTGROWBOX相同)HTSYSMENU系统菜单框HTVSCROLL窗口的垂直滚动栏HTZOOM最大化按钮非客户区鼠标消息ON_WM_NCLBUTTONDBLCLK()…voidCMainWindow::OnNcLButtonDblClk(UINTnHitTest,CPointpoint){if(nHitTest!=HTCAPTION)CWnd::OnNcLButtonDblClk(nHitTest,point);}非客户区鼠标消息NO_WM_NCHITTEST()…UINTCMainWindow::OnNcHitTest(CPointpoint){UINTnHitTest=CFrameWnd::OnNcHitTest(point);if(nHitTest==HTCLIENT){nHitTest=HTCAPTION;}returnnHitTest;}光标注册WNDCLASS,指定目标光标类型为类光标CStringstrWndClass=AfxRegisterWndClass(0,AfxGetApp()-LoadStandardCursor(IDC_CROSS),(HBRUSH)(COLOR_WINDOW+1),AfxGetApp()-LoadSteandardIcon(IDI_WINLOGO));Create(strWndClass,_T(“MouseCaptureDemo(CaptureEnabled)”));光标调用::SetCursor响应WM_SETCURSOR消息ON_WM_SETCURSOR()…BOOLCMainWindow::OnSetCursor(CWnd*pWnd,UINTnHitTest,UINTmessage){if(nHitTest==HTCLIENT){::SetCursor(m_hCursor);returnTRUE;}returnCFrameWnd::OnSetCursor(pWnd,nHitTest,message);}光标隐藏光标–::ShowCursor(FALSE);显示光标–::ShowCursor(TRUE);显示光标的次数与隐藏光标的次数相同,才能再次显示光标沙漏形光标显示沙漏形光标–CWaitCursorwc;CWaitCursor的构造函数显示沙漏形光标,其析构函数还原原来的光标如果在变量超出范围之前,还原光标可以调用CWaitCursor::Restore–wc.Restore();如果想自定义表现形式,可以重载CWinApp::DoWaitCursor键盘消息击键消息–WM_KEYDOWN、WM_KEYUP–WM_SYSKEYDOWN、WM_SYSKEYUP击键消息响应函数–Afx_msgvoidOnMsgName(UINTnChar,UINTnRepCnt,UINTnFlags)一般交给Windows去处理键盘消息字符消息ON_WM_CHAR()…voidCWainWindow::OnChar(UINTnChar,UINTnRepCnt,UINTnFlags){if(nChar==_T(‘a’)||(nChar==98)||(nChar==VK_RETURN)){dosomething}键盘消息虚拟键代码相应键VK_F1-VK_F12功能键F1-F12VK_NUMPAD0-VK_NUMPAD9数字键0-9NumLock开状态VK_CANCELCtrl-BreakVK_RETURNEnterVK_BACKBackspaceVK_TABTabVK_SHIFTShiftVK_CONTROLCtrlVK_MENUAlt键盘消息虚拟键代码相应键VK_PAUSEPsuseVK_ESCAPEEscVK_SPACESpacebarVK_PRIORPageUpVK_NEXTPageDownVK_ENDEndVK_HOMEHomeVK_INSERTInsertVK_DELETEDelete

1 / 23
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功