From be53e6f134499d29d0313b06ee619f622d12c614 Mon Sep 17 00:00:00 2001 From: DaniTheSkunk <> Date: Tue, 18 Apr 2023 04:32:33 +0000 Subject: [PATCH] opening window --- examples/simple.c | 84 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 8 deletions(-) diff --git a/examples/simple.c b/examples/simple.c index e8c5bdd..dcc2b44 100644 --- a/examples/simple.c +++ b/examples/simple.c @@ -1,18 +1,86 @@ #include -void render() { +#define WIN32_LEAN_AND_MEAN + +#include +#include + +LRESULT wndproc(HWND hwnd, u32 msg, WPARAM wparam, LPARAM lparam); + +wchar_t *sw_str_to_wstr(char *str) { + i32 size; + wchar_t *out; + + size = MultiByteToWideChar(CP_UTF8, 0, str, -1, 0, 0); + out = malloc(size); + MultiByteToWideChar(CP_UTF8, 0, str, -1, out, size); + + return out; } int main(int argc, char *argv[]) { - struct sw_window *win; - struct sw_renderer2d *ren; + WNDCLASSEXW wndclass = {0}; + HWND hwnd; - sw_init(argc, argv); + wndclass.cbSize = sizeof(wndclass); + wndclass.style = 0; + wndclass.lpfnWndProc = wndproc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = 0; + wndclass.hIcon = 0; + wndclass.hCursor = 0; + wndclass.hbrBackground = 0; + wndclass.lpszMenuName = 0; + wndclass.lpszClassName = L"Skunkworks"; + wndclass.hIconSm = 0; - win = sw_window_create(sw_vec2i(1280, 720), "example", 0); - ren = sw_renderer2d_create(); - sw_window_add_renderer(win, ren->renderer, render); - sw_window_run(win); + RegisterClassExW(&wndclass); + hwnd = CreateWindowExW( + 0, + L"Skunkworks", + L"Skunkworks test", + WS_POPUPWINDOW | WS_VISIBLE, + (1920 - 1280) / 2, + (1080 - 720) / 2, + 1280, + 720, + 0, + 0, + 0, + 0 + ); + + ShowWindow(hwnd, SW_SHOW); + + while (true) { + MSG msg; + + while (PeekMessageW(&msg, hwnd, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + } return 0; } + + +LRESULT wndproc(HWND hwnd, u32 msg, WPARAM wparam, LPARAM lparam) { + switch (msg) { + case WM_CLOSE: + case WM_KEYDOWN: + exit(0); + case WM_PAINT: { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hwnd, &ps); + + FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW + 1)); + + EndPaint(hwnd, &ps); + break; + } + } + + return DefWindowProcW(hwnd, msg, wparam, lparam); +}