正在加载图片...
第5单基本输入一键盘和标 / TODO: add construction code here b ctrldown=fals //初始化 b F8down=false //初始化 (3)在 WM KEYDOWN消息响应函数 onkey Downo中,实现按键状态的赋值,并在满足条件的 情况下,弹出提示对话框。代码如下 void cch5Demo2View:: Onkey Down(UINT nchar, UINT nRepcnt, UINT nFlags) / TODO: Add your message handler code here and/or call default if(nchar==VK CONTROL) //如果按下了【ctr1】键 b ctrldown=true if(nchar==VK F8) //如果按下了【E8】键 b Adown=true if(b ctrldown&&b F8down) //同时按下了【ctr1】键和【F8】键 b ctrldown=false AfxMessageBox("同时按下了ctr1键和F8键”);//弹出提示框 Cview:: OnKeyDown(nchar, nRepcnt, nFlags (4)在 WM KEYUP消息响应函数 Onkeyup(O中,实现按键状态的赋值。代码如下 void cch5 Demo 2View:: OnkeyUp(UINT nchar, UINT nRepCnt, UINT nElags) / TODO: Add your message handler code here and/or call default (nchar==vK CON //如果释放了【ctr1】键 if(nchar==VK E8) //如果释放了【F8】键 F Cview: OnkeyUp(nchar, nRepCnt, nFlags) 编译运行程序后,若用户同时按下了【Ctrl】键和【F8】键,就会弹出提示对话框,如图4.4 所 励志照亮人生编程改变命{ // TODO: add construction code here b_Ctrldown=false; //初始化 b_F8down=false; //初始化 } (3)在WM_KEYDOWN消息响应函数onkeyDown()中,实现按键状态的赋值,并在满足条件的 情况下,弹出提示对话框。代码如下: void CCh5Demo2View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default if(nChar==VK_CONTROL) //如果按下了【Ctrl】键 { b_Ctrldown=true; } if(nChar==VK_F8) //如果按下了【F8】键 { b_F8down=true; } if(b_Ctrldown&&b_F8down) //同时按下了【Ctrl】键和【F8】键 { b_Ctrldown=false; b_F8down=false; AfxMessageBox("同时按下了Ctrl键和F8键"); //弹出提示框 } CView::OnKeyDown(nChar, nRepCnt, nFlags); } (4)在WM_KEYUP消息响应函数Onkeyup()中,实现按键状态的赋值。代码如下: void CCh5Demo2View::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default if(nChar==VK_CONTROL) //如果释放了【Ctrl】键 { b_Ctrldown=false; } if(nChar==VK_F8) //如果释放了【F8】键 { b_F8down=false; } CView::OnKeyUp(nChar, nRepCnt, nFlags); } 编译运行程序后,若用户同时按下了【Ctrl】键和【F8】键,就会弹出提示对话框,如图4.4 所示。 75 励志照亮人生 编程改变命运 第 5 章 基本输入—键盘和鼠标消息
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有