implement window drawing
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/build/*
|
||||
!/build/.gitk
|
||||
0
build/.gitk
Normal file
0
build/.gitk
Normal file
9
code/.clangd
Normal file
9
code/.clangd
Normal file
@@ -0,0 +1,9 @@
|
||||
CompileFlags:
|
||||
Add:
|
||||
- "--target=x86_64-w64-windows-gnu"
|
||||
- "-isystem"
|
||||
- "/usr/lib/zig/libc/include/any-windows-any"
|
||||
- "-isystem"
|
||||
- "/usr/lib/zig/libc/include/generic-musl"
|
||||
- "-D_WIN32"
|
||||
- "-D_X86_64_"
|
||||
5
code/Makefile
Normal file
5
code/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
comp:
|
||||
zig c++ --target=x86_64-windows -o ../build/win32_handmade.exe win32_handmade.cpp -lgdi32
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm ../build/*
|
||||
83
code/win32_handmade.cpp
Normal file
83
code/win32_handmade.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user