From bc47a2e646f7045437ae615127125d906656da2c Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 26 Oct 2020 13:56:32 +0200 Subject: [PATCH] fixed build on windows --- .gitignore | 1 + Makefile | 1 + test_win.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 0932ecf..67fb88b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.d *.swp test +test.exe diff --git a/Makefile b/Makefile index cf2a010..91bf8b6 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ sys ?= $(shell uname -s | sed 's/MINGW.*/mingw/') ifeq ($(sys), mingw) src += test_win.c CFLAGS += -DBUILD_WIN32 + LDFLAGS += -lgdi32 else src += test_x11.c CFLAGS += -DBUILD_X11 diff --git a/test_win.c b/test_win.c index f1e75a5..ff13e56 100644 --- a/test_win.c +++ b/test_win.c @@ -18,7 +18,7 @@ static HWND win; static HINSTANCE hinst; static HDC dc; static int win_width, win_height; - +static int quit; int WINAPI WinMain(HINSTANCE hinst_, HINSTANCE hprev, char *cmdline, int showcmd) { @@ -56,16 +56,63 @@ int WINAPI WinMain(HINSTANCE hinst_, HINSTANCE hprev, char *cmdline, int showcmd end: ggfx_shutdown(); - ReleaseDC(dc); + ReleaseDC(win, dc); DestroyWindow(win); UnregisterClass("gphgfxtest", hinst); return 0; } + +static void redraw(void) +{ + RECT rect; + HBRUSH brush; + + rect.left = rect.top = 0; + rect.right = win_width; + rect.bottom = win_height; + + brush = CreateSolidBrush(RGB(128, 0, 0)); + + FillRect(dc, &rect, brush); +} + +static void reshape(int x, int y) +{ +} + +static void keydown(int key, int x, int y) +{ + switch(key) { + case 27: + quit = 1; + break; + } +} + +static void keyup(int key, int x, int y) +{ +} + +static void button(int bn, int st, int x, int y) +{ +} + +static void motion(int x, int y) +{ +} + static int create_window(const char *title, int width, int height) { - if(!(win = CreateWindow("gphgfxtest", title, WS_OVERLAPPEDWINDOW, 0, 0, width, - height, 0, 0, hinst, 0))) { + RECT rect; + + rect.left = rect.top = 0; + rect.right = width; + rect.bottom = height; + AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, 0); + + if(!(win = CreateWindow("gphgfxtest", title, WS_OVERLAPPEDWINDOW, 0, 0, + rect.right - rect.left, rect.bottom - rect.top, 0, 0, hinst, 0))) { fprintf(stderr, "failed to create window\n"); return -1; } @@ -162,5 +209,5 @@ static void handle_mbutton(int bn, int st, WPARAM wparam, LPARAM lparam) { int x = lparam & 0xffff; int y = lparam >> 16; - mouse(bn, st, x, y); + button(bn, st, x, y); } -- 1.7.10.4