#include <Windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CLOSE:
PostQuitMessage(69); //exitCode -> wParam
break;
case WM_KEYDOWN:
if (wParam == 'F')
{
SetWindowText(hwnd, "F Keydown");
}
break;
case WM_KEYUP:
if (wParam == 'F')
{
SetWindowText(hwnd, "F Keyup");
}
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
int CALLBACK WinMain(
_In_ HINSTANCE hInstance, //handle to instance
_In_opt_ HINSTANCE hPrevInstance, //handle to previous instance
_In_ LPSTR IpCmdLine, //long pointer to string
_In_ int nCmdShow
)
{
const auto pClassName = "hw3dbutts";
// register window class
WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof wc; //size of the struct
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc; //process func
wc.cbClsExtra = 0;
wc.cbWndExtra = 0; // 0 in usual
wc.hInstance = hInstance;
wc.hIcon = nullptr; //handle to icon
wc.hCursor = nullptr;
wc.hbrBackground = nullptr; // handle to backgroung brush
wc.lpszMenuName = nullptr;
wc.lpszClassName = pClassName;
wc.hIconSm = nullptr; //handle to small icon
RegisterClassEx(&wc);
//create window instance
HWND hwnd = CreateWindowEx(
0, pClassName,
"Happy Hard Window",
WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
200, 200, 640, 480,
nullptr, nullptr, hInstance, nullptr
);
//show the damn window
ShowWindow(hwnd, SW_SHOW);
//message pump
MSG msg;
BOOL gResult;
while (gResult = GetMessage(&msg, nullptr, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (gResult == -1)
{
return -1;
}
else
{
return (int)msg.wParam;
}
}
标签:wParam,窗口,handle,CG,nullptr,消息,hwnd,msg,wc
From: https://blog.csdn.net/m0_73669127/article/details/142066033