关于文本输出的的错误
写一个程序时出现问题以下是源代码
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
TCHAR psz;
然后出现了下面的情况
这里测试的是长按不放且不锁定CAPS键和不按住SHIFT键的A键(Z键的为测试时点错)
https://i0.hdslb.com/bfs/album/72ffc2704b53864f205a8ef39875b669cd852615.png@518w.webp
emmm 图片有点模糊
而将WM_CHAR中的“ cxount += 1 ”语句删掉
就变成了这种情况(注:下面的图片测试时将字体的基线从"TA_RIGHT"改为了"TA_LEFT" )
https://i0.hdslb.com/bfs/album/483463e03ec6e5279e7c6a1790438b2a996f4aa8.png@518w.webp
为什么第一张图片中明明按的是小写的"A"键,却"a"前面又会出现"A",
而第二张将"count += 1"删掉就只出现了“a”?请问有人能解答一下吗 还是我的代码有问题? 我这里检查帖子时发现我这里看代码有点问题 这里再发一遍
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
TCHAR psz;
static int cxChar ,cyChar, cxCount = 0, cyCount = 0;
TEXTMETRIC tm;
switch (message)
{
case WM_CREATE:
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight;
ReleaseDC(hwnd, hdc);
return 0;
case WM_KEYDOWN:
case WM_CHAR:
hdc = GetDC(hwnd);
SetTextAlign(hdc, TA_LEFT | TA_TOP);
psz = (TCHAR)wParam;
TextOut(hdc, cxCount * cxChar, cyCount * cyChar, &psz, 1);
if (cxCount >= 100)
{
cxCount = 0;
cyCount += 1;
}
ReleaseDC(hwnd, hdc);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
页:
[1]