VC它不听话,9命啊

来源:百度知道 编辑:UC知道 时间:2024/06/10 20:16:48
char szChar[10];
PAINTSTRUCT ps;
int j=0;

LRESULT CALLBACK WinSunProc(
HWND hwnd, // 窗口的一个句柄
UINT uMsg, // 消息标识符
WPARAM wParam, // 第一个消息参数
LPARAM lParam // 第二个消息参数
)
{ HDC hdc;

switch(uMsg)
{
case WM_CHAR:
{
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);

memset(szChar, 0, sizeof(szChar)); //格式化内存
sprintf(szChar,"%c",wParam);
TextOut(hdc,j,0,szChar,strlen(szChar));

EndPaint(hwnd,&ps);
InvalidateRect(hwnd,NULL,true);

break;
}
case WM_PAINT:
{

j=j+4;
hdc=BeginPaint(hwnd,&ps);

char sum[200];
strcat(sum,szChar);
//memset(sum, 0, sizeof(sum));
TextOut(hdc,j,0,sum,strlen(sum));

EndPaint(hwnd,&ps);
break;
}
szChar是键盘输入的,sum是累计键盘输入的,最后输出
要做类似打字程序一样,每隔1个字在输出,输入的信息.

--------------你的DC用的不对----------
hdc=BeginPaint(hwnd,&ps); //难道你忘记了吗?BeginPaint()只能用在处理WM_PAINT消息呀!!!!
//如果不是WM_PAINT消息,你就应该用GetDC(),或者别的获取DC的方法。

memset(szChar, 0, sizeof(szChar));
sprintf(szChar,"%c",wParam);
TextOut(hdc,j,0,szChar,strlen(szChar));

EndPaint(hwnd,&ps); //