Files
handmade_hero/code/win32_handmade.cpp
2026-01-24 17:52:28 +02:00

84 lines
2.2 KiB
C++

#include <stdio.h>
#include <windows.h>
#include <wingdi.h>
LRESULT CALLBACK MainWindowCallback(HWND window, UINT message, WPARAM wParam,
LPARAM lParam) {
LRESULT res = 0;
switch (message) {
case WM_SIZE: {
printf("WM_SIZE\n");
} break;
case WM_DESTROY: {
printf("WM_DESTROY\n");
} break;
case WM_CLOSE: {
printf("WM_CLOSE\n");
} break;
case WM_PAINT: {
PAINTSTRUCT paint;
HDC deviceContext = BeginPaint(window, &paint);
int height = paint.rcPaint.bottom - paint.rcPaint.top;
int width = paint.rcPaint.right - paint.rcPaint.left;
int x = paint.rcPaint.left;
int y = paint.rcPaint.top;
static DWORD operation = WHITENESS;
PatBlt(deviceContext, x, y, width, height, operation);
if (operation == WHITENESS) {
operation = BLACKNESS;
} else {
operation = WHITENESS;
}
EndPaint(window, &paint);
} break;
case WM_ACTIVATEAPP: {
printf("WM_ACTIVATEAPP\n");
} break;
default: {
// printf("WM_ACTIVATEAPP\n");
res = DefWindowProc(window, message, wParam, lParam);
} break;
}
return res;
}
int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prevInstance,
LPSTR commandLine, int showCode) {
WNDCLASS WindowClass = {0};
WindowClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
WindowClass.lpfnWndProc = MainWindowCallback;
// WindowClass.cbClsExtra = ;
// WindowClass.cbWndExtra = ;
WindowClass.hInstance = instance;
// WindowClass.hIcon = ;
// WindowClass.hCursor = ;
// WindowClass.lpszMenuName = ;
WindowClass.lpszClassName = "HandmadeHeroWindowClass";
if (RegisterClass(&WindowClass)) {
HWND windowHandle = CreateWindowEx(
0, WindowClass.lpszClassName, "Handmade Hero",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, instance, 0);
if (windowHandle) {
MSG message;
for (;;) {
BOOL msgResult = GetMessage(&message, 0, 0, 0);
if (msgResult > 0) {
TranslateMessage(&message);
DispatchMessage(&message);
} else {
break;
}
}
} else {
// TODO: log?
}
} else {
// TODO: log?
}
return (0);
}