跟着小甲鱼敲代码,为什么按键盘没反应
#include <windows.h>#include<strsafe.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("MyWindows");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName,
TEXT("hello"),
WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
static int cxClientMax, cyClientMax, cxClient, cyClient, cxChar, cyChar;
static int cLinesMax, cLines;//客户区最大化可以容纳的行数,当前申请的内存块里面有的消息行数
static PMSG pmsg;
static RECT RectScroll;
static TCHAR szTop[] = TEXT("Message Key Char Repeat Scan Ext Alt Prev Tran");
static TCHAR szUnd[] = TEXT("_______ ___ ___ ______ ____ ___ ___ ____ ____");
static TCHAR* szFormat = { TEXT("%-13s %3d %-15s%c%6u %4d %3s %4s %4s"),
TEXT("%-13s 0x%04X%1s%c %6u %4d %3s %3s %4s %4s")};
static TCHAR* szYes = TEXT("Yes");
static TCHAR* szNo = TEXT("No");
static TCHAR* szDown = TEXT("Down");
static TCHAR* szUp = TEXT("Up");
static TCHAR * szMessage[] = { TEXT("WM_KEYDONE"),TEXT("WM_KEYUP"),TEXT("WM_CHAR"),TEXT("WM_DEADCHAR"),
TEXT("WM_SYSKEYDONE"),TEXT("WM_SYSKEYUP"),TEXT("WM_SYSCHAR"),TEXT("WM_SYSDEADCHAR") };
HDC hdc;
int iType;
size_t iTarget;
PAINTSTRUCT ps;
TCHAR szBuffer, szKeyName;
TEXTMETRIC tm;
int LinesTemp;//当前需要显示的行数
switch (message)
{
case WM_CREATE:
//不管,继续执行
case WM_DISPLAYCHANGE:
//客户区最大化或者最小化会产生这个消息
cxClientMax = GetSystemMetrics(SM_CXMAXIMIZED);
cyClientMax = GetSystemMetrics(SM_CYMAXIMIZED);
hdc = GetDC(hwnd);
//设置等宽字体
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight;
ReleaseDC(hwnd, hdc);
if (pmsg)
{
free(pmsg);
}
//计算客户区最大高度可以容纳多少行
cLinesMax = cyClientMax / cyChar;
//申请一块内存,大小为客户区最大高度可以容纳的行数*一行多大(MSG类型占用多大空间)
pmsg = (PMSG)malloc( cLinesMax * sizeof(MSG));
cLines = 0;
//如果内存申请失败
if (pmsg == NULL)
{
MessageBox(hwnd, TEXT("内存申请失败"), TEXT("Error"), MB_OK);
PostQuitMessage(0);
}
case WM_SIZE:
if (message == WM_SIZE)
{
cxClient = LOWORD(lparam);
cyClient = HIWORD(lparam);
}
//计算滚动的矩形
RectScroll.left = 0;
RectScroll.right = cxClient;
RectScroll.top = cyChar;
RectScroll.bottom = cyClient;
InvalidateRect(hwnd, NULL, TRUE);
return 0;
case WM_KEYDOWN:
case WM_KEYUP:
case WM_CHAR:
case WM_DEADCHAR:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_SYSCHAR:
case WM_SYSDEADCHAR:
//这几个消息都这么干
for (int i = cLinesMax - 1; i > 0; i--)
{
pmsg = pmsg;
}
pmsg.hwnd = hwnd;
pmsg.message = message;
pmsg.lParam = lparam;
pmsg.wParam = wparam;
//cLines这个变量的作用很难解释...
cLines = min(cLines + 1, cLinesMax);
ScrollWindow(hwnd, 0, -cyChar, & ScrollWindow, &ScrollWindow);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
//设置背景为透明色
SetBkMode(hdc, TRANSPARENT);
StringCchLength(szTop, 1024, &iTarget);
TextOut(hdc, 0, 0, szTop, iTarget);
StringCchLength(szUnd, 1024, &iTarget);
TextOut(hdc, 0, 0, szUnd, iTarget);
//当前需要显示的行数 = 当前内存块里面有的消息行数 和 当前客户区最多可以容纳的行数 中的小的那个,减一是因为最上面那一行显示的有文字
LinesTemp = min(cLines, cyClient / cyChar - 1);
for (size_t i = 0; i < min(cLines, cyClient / cyChar - 1); i++)
{
iType = (pmsg.message == WM_CHAR || pmsg.message == WM_SYSCHAR || pmsg.message == WM_DEADCHAR || pmsg.message == WM_SYSDEADCHAR);
GetKeyNameText(pmsg.lParam, szKeyName, 32);
StringCchPrintf(szBuffer, sizeof(szBuffer), szFormat,
szMessage.message - WM_KEYFIRST],
pmsg.wParam,
(PTSTR)(iType ? TEXT("") : szKeyName),
(TCHAR)(iType ? pmsg.wParam : ' '),
LOWORD(pmsg.lParam),
HIWORD(pmsg.lParam) & 0xff,
0x01000000 & pmsg.lParam ? szYes : szNo,
0x20000000 & pmsg.lParam ? szYes : szNo,
0x40000000 & pmsg.lParam ? szDown : szUp,
0x80000000 & pmsg.lParam ? szUp : szDown);
StringCchLength(szBuffer, sizeof(szBuffer), &iTarget);
TextOut(hdc, 0, (cyClient / cyChar - 1 - i)*cyChar, szBuffer, iTarget);
TextOut(hdc, 100, 100, TEXT("kkkk"), 4);
TextOut(hdc, 100, 100, TEXT("kkkk"), 4);
}
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wparam, lparam);
} fishc助手去哪里了? fishc助手挂了????????????????? @FishC 哪要是不跟着小甲鱼敲代码,键盘会不会有反应?{:5_108:} @FishC sun_chuan 发表于 2024-8-9 00:38
fishc助手挂了?????????????????
fishc确实不见了
页:
[1]