Created
February 12, 2021 16:03
-
-
Save rinsuki/e6d5697f9043d3230eecf8894341f75e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <wingdi.h> | |
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { | |
PAINTSTRUCT ps; | |
HDC hdc; | |
static int x = 100; | |
static int y = 100; | |
switch (msg) { | |
case WM_TIMER: | |
// main loop | |
if (GetAsyncKeyState(0x57)) { | |
y--; | |
} | |
if (GetAsyncKeyState(0x53)) { | |
y++; | |
} | |
if (GetAsyncKeyState(0x41)) { | |
x--; | |
} | |
if (GetAsyncKeyState(0x44)) { | |
x++; | |
} | |
InvalidateRect(hWnd, NULL, FALSE); | |
return 0; | |
case WM_PAINT: | |
hdc = BeginPaint(hWnd, &ps); | |
SetTextColor(hdc, RGB(255, 0, 0)); | |
TextOut(hdc, x, y, "Hello, World!", 13); | |
EndPaint(hWnd, &ps); | |
return 0; | |
case WM_CREATE: | |
SetTimer(hWnd, 1, 1000 / 60, NULL); | |
return 0; | |
case WM_DESTROY: | |
KillTimer(hWnd, 1); | |
PostQuitMessage(0); | |
return 0; | |
default: | |
return DefWindowProc(hWnd, msg, wParam, lParam); | |
} | |
} | |
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { | |
WNDCLASS wc; | |
MSG msg; | |
ZeroMemory(&wc, sizeof(WNDCLASS)); | |
wc.lpfnWndProc = WndProc; | |
wc.hInstance = hInstance; | |
wc.lpszClassName = TEXT("MainWindow"); | |
wc.hbrBackground = WHITE_BRUSH; | |
if (!RegisterClass(&wc)) return 0; | |
HWND hWnd = CreateWindow( | |
wc.lpszClassName, | |
TEXT("Main Window"), | |
WS_OVERLAPPEDWINDOW, | |
CW_USEDEFAULT, | |
CW_USEDEFAULT, | |
1280, | |
720, | |
NULL, | |
NULL, | |
hInstance, | |
NULL | |
); | |
ShowWindow(hWnd, nCmdShow); | |
UpdateWindow(hWnd); | |
while (GetMessage(&msg, NULL, 0, 0)) { | |
TranslateMessage(&msg); | |
DispatchMessage(&msg); | |
} | |
return msg.wParam; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment