




已阅读5页,还剩17页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Visual C+ 与面向对象程序设计 第4章 VC+编程中关于键盘 与鼠标消息的响应 德州学院 计算机系 主讲教师 韩金姝 1 德州学院 计算机系 本章主要内容 v 键盘在应用程序中的应用 v 键盘操作应用举例 v 鼠标在应用程序中的应用 v 鼠标应用举例 v 例题和习题中涉及的函数 2 德州学院 计算机系 键盘在应用程序中的应用 v键盘消息的生成 用户按键 键盘中断处理程序对所击键编码(扫描码-虚 拟码,以实现设备无关性) 调用Windows的USER.EXE程序生成键盘消息 到消息队列等候处理 3 德州学院 计算机系 键盘在应用程序中的应用 v 键盘消息分类 按键消息 字符消息 v 输入焦点和插字符 4 德州学院 计算机系 按键消息 v 按键消息分类 系统按键消息: Alt键+相关输入键组合产生的消息。由 Windows系统内部处理。WM_SYSKEYDOWN/ WM_SYSKEYUP 非系统按键消息: 不使用Alt键组合的消息。WM_KEYDOWN/ WM_KEYUP 5 德州学院 计算机系 按键消息 v 按键消息的构成: 包含扫描码、虚拟码以及其他与击键有 关的消息。放在wParam和lParam中 虚拟码是与设备无关的键盘编码,其值 存放在按键消息的wParam参数中(表4- 1) lParam不同位数的含义(表4-2) 6 德州学院 计算机系 字符消息 v WinMain函数的消息循环中 TranslateMessage函数把按键消息 转化为字符消息,当键盘驱动程序 把键盘字符映射成ASCII码后,产生 字符消息。(表4-3) 7 德州学院 计算机系 输入焦点和插字符 v 输入焦点 应用程序的众多窗口共享键盘,仅有一个窗口 过程能接收键盘消息,称为有输入焦点的窗口 。窗口函数通过捕获WM_SETFOCUS/ WM_KILLFOCUS消息以确定当前窗口是否具有输 入焦点。 v 插字符 Windows操作系统用插字符指示当前正文位置 。插字符是应用程序共享的系统资源。 只有拥有“输入焦点”的窗口才能拥有插字符。 8 德州学院 计算机系 键盘操作应用举例 v 例41(P51):键盘消息处理程序 单击一个键后,在窗口中依次显示出:按键消 息、参数wParam的值,若为字符消息时,还显示 出相应字母、重复记位数、OEM扫描码、扩展键 标志、Alt键按下标志、按键的先前状态和转换 状态等内容。 演示程序1 9 德州学院 计算机系 键盘操作应用举例 v 习题4.2(P69): 设计一个窗口,在该窗口中练习键盘的响应, 要求如下: (1)单击键盘的向上箭头时,窗口中显示 ”You had hitted the up key” (2)单击键时,窗口中显示”You had hitted the SHIFT key” (3)单击键时,窗口中显示”You had hitted the CTRL key” 演示程序2 10 德州学院 计算机系 鼠标在应用程序中的应用 v鼠标是一种定位输入设备,有单击、双击和 拖动功能。 vWINDOWS中通过光标指示当前鼠标位置。系统 预定义光标形式见表44 v应用程序加载光标资源: 在定义窗口类或者在程序中调用 LoadCursor(hThisInst,lpszCursorname) 11 德州学院 计算机系 鼠标在应用程序中的应用 v 鼠标消息的产生: Windows操作系统通过鼠标设备驱动程序接收 鼠标输入。鼠标设备驱动程序在启动Windows 时装入。 v 在窗口内有鼠标事件发生 窗口接收一个鼠标事件 产生用户区鼠标消息 v常用的鼠标消息:表45 12 德州学院 计算机系 鼠标在应用程序中的应用 v 鼠标消息的构成: 通过lParam和wParam,可以确定鼠标的位置和 鼠标键的状态。 l lParam:包含鼠标坐标位置。 低位X;高位Y。 l wParam:指示各种虚键状态的值。表4-6。 13 德州学院 计算机系 鼠标在应用程序中的应用 v鼠标消息的处理: 1.非用户区鼠标消息: 当在一个窗口的用户区以外的地方(例如在窗 框的菜单、滚动条、工具条和标题条等处)产 生一个鼠标事件,就将产生一个非用户区鼠标 消息。 非用户区鼠标消息,不由应用程序具体处理, 而是送往DefWindowProc( )。 14 德州学院 计算机系 鼠标在应用程序中的应用 v鼠标消息的处理: 2. 用户区鼠标消息: 处理时要考虑,鼠标左键按下同时检测Shift和 Ctrl键: Case WM_LBUTTONDOWN: if (wParam Case WM_LBUTTONUP: break; 15 德州学院 计算机系 鼠标在应用程序中的应用 v鼠标双击消息的处理: v若要使窗口函数能接收鼠标双击消息,在注册 窗口时必须注明该窗口类具有CS_DBLCLKS属性 。否则是两次双击 wndclass.style=CS_HEADRAW|CS_VERDARW|CS_DB LCLKS v双击的时间间隔:默认0.5s vSetDoubleClickTime()重新设定 16 德州学院 计算机系 鼠标在应用程序中的应用 v 窗口对鼠标消息的捕获: 1.SetCapture(hWnd):可以使Windows发 送的所有鼠标消息均定向到某一窗口,而不管 鼠标的光标处于何处。 2. ReleaseCapture( ):释放鼠标,以 使其它窗口正常接收鼠标消息。因为:一旦从 窗口捕获了鼠标,系统的键盘功能就暂时失效 ,其它窗口也无法得到鼠标消息。 17 德州学院 计算机系 鼠标应用举例 v例4-3(P65):鼠标输入示范程序 通过本程序,学习如何相应鼠标信息、改变光 标形状等用法,如用户在窗口的不同区域移动 鼠标时,光标将显示不同的形状,如“十”字 形光标、“水平双箭头”光标、”垂直双箭头 “光标、”沙露“光标等。 演示程序3 18 德州学院 计算机系 例题和习题中涉及的函数 v RECT vThe RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle. vtypedef struct _RECT LONG left; LONG top; LONG right; LONG bottom; RECT, *PRECT; vMembers vleft Specifies the x-coordinate of the upper-left corner of the rectangle. vtop Specifies the y-coordinate of the upper-left corner of the rectangle. vright Specifies the x-coordinate of the lower-right corner of the rectangle. vbottom Specifies the y-coordinate of the lower-right corner of the rectangle. 19 德州学院 计算机系 例题和习题中涉及的函数 ScrollWindow function scrolls the contents of the specified windows client area. BOOL ScrollWindow ( HWND hWnd, int XAmount, int YAmount, const RECT *lpRect, const RECT *lpClipRect ); Parameters hWnd in Handle to the window where the client area is to be scrolled. XAmount in Specifies the amount, in device units, of horizontal scrolling. If the window being scrolled has the CS_OWNDC or CS_CLASSDC style, then this parameter uses logical units rather than device units. This parameter must be a negative value to scroll the content of the window to the left. YAmount in Specifies the amount, in device units, of vertical scrolling. If the window being scrolled has the CS_OWNDC or CS_CLASSDC style, then this parameter uses logical units rather than device units. This parameter must be a negative value to scroll the content of the window up. lpRect in Pointer to the RECT structure specifying the portion of the client area to be scrolled. If this parameter is NULL, the entire client area is scrolled. lpClipRect in Pointer to the RECT structure containing the coordinates of the clipping rectangle. Only device bits within the clipping rectangle are affected. Bits scrolled from the outside of the rectangle to the inside are painted; bits scrolled from the inside of the rectangle to the outside are not painted. 20 德州学院 计算机系 例题和习题中涉及的函数 Wsprintf formats and stores a series of characters and values in a buffer. Any arguments are converted and copied to the output buffer according to the corresponding format specification in the format string. The function appends a terminating null character to the characters it writes, but the return value does not include the terminating null character in its character count. If the function succeeds, the return value is the number of characters stored in the output buffer, not counting the terminating null character. If the function fails, the return value is less than the length of the expected output. To get extended error information, call GetLastError. . 21 德州学院 计算机系 ValidateRect validates the client area within a rectangle by removing the rectangle from the update region of the specified window hWnd in Handle to the window whose update region is to be modified. If this parameter is NULL, the system invalidates and redraws all windows and sends the WM_ERASEBKGND and WM_NCPAI
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 舞蹈教育机构舞蹈教师学生辅导与升学合同
- 民政局养老安全培训课件
- 工厂员工岗前安全培训课件
- 金融改革面试题库及答案
- 教师美术面试题库及答案
- 互联网+养老护理服务项目可行性研究及实施计划2025
- 2025年教育平台用户增长策略优化:国际教育市场拓展报告
- 路政执法证管理办法
- 2025年村居后备干部考试题库及参考答案
- 2025年村后备干部测试题及答案
- 第一单元 分数乘法(单元测试)(含答案)-2024-2025学年六年级上册人教版数学
- 军用无人机课件
- 303智能化综采工作面作业规程
- 中建基础设施公司“主要领导讲质量”
- 《射频通信全链路系统设计》 课件 第5、6章 射频通信发射机设计、射频通信时钟系统设计
- 山东省二年级下册数学期末考试试卷
- DBJ46-070-2024 海南省民用建筑外门窗工程技术标准
- GB/T 44621-2024粮油检验GC/MS法测定3-氯丙醇脂肪酸酯和缩水甘油脂肪酸酯
- 校园天眼平台建设方案
- 集合间的基本关系课件
- 就业困难人员认定申请表
评论
0/150
提交评论