没有合适的资源?快使用搜索试试~ 我知道了~
mfc 实现键盘消息响应
4星 · 超过85%的资源 需积分: 45 146 下载量 58 浏览量
2009-11-15
19:24:44
上传
评论 5
收藏 40KB DOC 举报
温馨提示
试读
3页
设计一个窗口,在该窗口中练习键盘的响应,要求如下:单击键盘上的向上箭头时,窗口中显示“You had hitted the up key”;单击<Shift>键时,窗口中显示“You had hitted the SHIFT key”;单击<Ctrl>键时,窗口中显示“You had hitted the CTRL key”;单击<Ctrl+A>键时,窗口中显示“You had hitted the CTRL A key”;单击<Shift+B>键时,窗口中显示“You had hitted the SHIFT B key”。
资源推荐
资源详情
资源评论
题目:
设计一个窗口,在该窗口中练习键盘的响应,要求如下:单击键盘上的向上箭头时,
窗口中显示“You had hitted the up key”;单击<Shift>键时,窗口中显示“You had hitted the
SHIFT key”;单击<Ctrl>键时,窗口中显示“You had hitted the CTRL key”;单击<Ctrl+A>键
时,窗口中显示“You had hitted the CTRL A key”;单击<Shift+B>键时,窗口中显示“You had
hitted the SHIFT B key”。
代码:
#include<windows.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM
lParam);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
//主函数
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,
int nCmdShow)
{
MSG Message;
if(!InitWindowsClass(hInstance)) return FALSE;
if(!InitWindows(hInstance,nCmdShow))return FALSE;
while(GetMessage(&Message,0,0,0))//消息循环
{TranslateMessage(&Message);
DispatchMessage(&Message);}
return Message.wParam;}
long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam)
{HDC hDC; //定义设备环境句柄.
PAINTSTRUCT ps; //定义包含绘图信息的结构体变量
HPEN hPen; //定义画笔句柄。
HBRUSH hBrush; //定义画刷句柄
//以下定义输出的字符串。
static char cUp[]="You had hitted the UP key";
static char cCtrl[]="You had hitted the Ctrl key";
static char cShift[]="You had hitted the SHIFT key";
static char cCtrl_A[]="You had hitted the CTRL A key";
static char cShift_B[]="You had hitted the SHIFT B key";
//下面定义并初始化按键标志变量。
static BOOL nUpKeyDown=FALSE,
nShiftKeyDown=FALSE,
nCtrlKeyDown=FALSE,
liqiao123
- 粉丝: 3
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页