我正在尝试捕获 WM_CHAR 键的值,然后将所有捕获的值放入一个字符串中。我尝试将按下的键值 2、3、4 和 5 与 _tcscat 连接,生成的 TCHAR 字符串看起来像这样“22232323423423452345”我想知道如何使 TCHAR 字符串看起来像 2345。以下是我的代码有。
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static PMSG pmsg ;
int i, iType ;
int StrLen;
TCHAR StrBuf[9];
static TCHAR tBuf[32];
TCHAR MyTchar[8] = TEXT ("A");
WORD wCharCode;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect(hwnd, &rect);
SelectObject (hdc, GetStockObject (SYSTEM_FONT)) ;
SetBkMode (hdc, TRANSPARENT) ;
for (i = min (cLines, cLinesMax), cScreenLine=1; i>0 ; i--, cScreenLine++)
{
iType = pmsg[i-1].message == WM_CHAR ;
if (!iType)
{
StrLen= wsprintf(StrBuf, TEXT("%s"), TEXT(" "));
}
else
{
wCharCode = (WORD)(pmsg[i-1].wParam & 0xffff);
memcpy(&MyTchar, &wCharCode, 2);
StrLen = wsprintf(StrBuf[2], TEXT("%s"), &MyTchar);
_tcscat(tBuf, MyTchar);
}
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
}