C++处理键盘输入的方法
这篇文章主要介绍了C++处理键盘输入的方法,是C++程序设计中非常实用的技巧,需要的朋友可以参考下
本文实例讲述了C++处理键盘输入的方法,可实现简单处理键盘输入,分享给大家供大家参考。具体实现方法如下:
需要响应WM_CHAR消息:
复制代码 代码如下:
#include <string>
static std::string str;
static std::string str;
在wm_char中:
复制代码 代码如下:
str = str + char(wParam);
::InvalidateRect(hWnd, NULL, 0);
return 0;
::InvalidateRect(hWnd, NULL, 0);
return 0;
在wm_paint中:
复制代码 代码如下:
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
::TextOut(hdc, 0, 0, str.c_str(),str.length());
EndPaint(hWnd, &ps);
break;
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
::TextOut(hdc, 0, 0, str.c_str(),str.length());
EndPaint(hWnd, &ps);
break;
希望本文所述对大家的C++程序设计有所帮助。
- 上一篇:C++画正弦线实例代码
- 下一篇:C++中的Lambda表达式详解
精彩图集
精彩文章