求解!!!

Phantasy 2004-04-07 09:36:17
首先调用TextOut( )函数的原因是为了释放以前显示的所有字符。由于Windows 3.1 是基于图形的系统,其字符长短不同,而且一个字符覆盖另一个字符并不能完全擦除前面的字符。例如,如果你在w 后键入i,如果不亲自擦除w,则其一部分仍会显示在屏幕上
但是还是不能完全擦除!请问是哪里的问题?
/*Process WM_CHAR messages.*/

#include<windows.h>
#include<string.h>
#include<stdio.h>

LRESULT CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);

char *szWinName ="MyWin"; /*name of window class */
char str[255] = " "; /* holds output string */
int WINAPI WinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,
LPSTR lpszArgs,int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
/* Define a window class. */
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst; /* handle to this instance */
wcl.lpszClassName = szWinName; /* window class name */
wcl.lpfnWndProc = WindowFunc; /* window function */
wcl.style = 0; /* default style */
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION), /* standard icon */
wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO); /* small icon */
wcl.hCursor = LoadCursor(NULL, IDC_ARROW); /* cursor style */
wcl.lpszMenuName = NULL; /* no menu */
wcl.cbClsExtra = 0; /* no extra */
wcl.cbWndExtra = 0; /* information needed * /
/* Make the window white. */
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

/* Register the window class. */
if(!RegisterClassEx(&wcl)) return 0;

/* Now that a window class has been registered, a window
can be created. */
hwnd = CreateWindow(
szWinName, /* name of window class */
"Processing WM_CHAR Messages", /* title */
WS_OVERLAPPEDWINDOW, /* window style - normal */
CW_USEDEFAULT, /* X coordinate - let Windows decide */
CW_USEDEFAULT, /* Y coordinate - let Windows decide */
CW_USEDEFAULT, /* width - let Windows decide */
CW_USEDEFAULT, /* height - let Windows decide */
HWND_DESKTOP, /* no parent window */
NULL, /* no menu */
hThisInst, /* handle of this instance of the program */
NULL /* no additional arguments */
);

/* Display the window. */
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);

/* Create the message loop. */
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg); /* translate keyboard messages */
DispatchMessage(&msg); /* return control to Windows 98 */
}
return msg.wParam;

}

/* This function is called by Windows 98 and is passed
messages from the message queue.
*/
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc;

switch(message)
{
case WM_CHAR: /* process keystroke */
hdc = GetDC(hwnd); /* get device context */
TextOut(hdc, 1, 1, " ", 1); /* erase old character */
sprintf(str, "%c", (char) wParam); /* stringize character */
TextOut(hdc, 1, 1, str, strlen(str)); /* output char */
ReleaseDC(hwnd, hdc); /* release device context */
break;

case WM_DESTROY: /* terminate the program */
PostQuitMessage(0);
break;
default:
/* Let Windows 98 process any messages not specified in
the preceding switch statement. */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
...全文
32 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bhut 2004-04-07
  • 打赏
  • 举报
回复
我都已经回答过了
bhut 2004-04-07
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2920/2920526.xml?temp=.8940241
YunLion 2004-04-07
  • 打赏
  • 举报
回复
修改部分代码:
case WM_CHAR: /* process keystroke */
{
static char chOld;
hdc = GetDC(hwnd); /* get device context */
COLORREF clrOld = SetTextColor(hdc, GetBkColor(hdc));
sprintf(str, "%c", chOld); /* stringize character */
TextOut(hdc, 1, 1, str, strlen(str)); /* erase old character */
sprintf(str, "%c", (char) wParam); /* stringize character */
SetTextColor(hdc, clrOld);
TextOut(hdc, 1, 1, str, strlen(str)); /* output char */
ReleaseDC(hwnd, hdc); /* release device context */
chOld = (char) wParam;
break;
}

16,490

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧