From 3e14f5461f24b81cd578f1838283fe3e239be023 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 3 Apr 2024 00:15:22 +0200 Subject: [PATCH] update --- UI/window.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 UI/window.h diff --git a/UI/window.h b/UI/window.h new file mode 100644 index 0000000..dd4fda6 --- /dev/null +++ b/UI/window.h @@ -0,0 +1,71 @@ +#ifndef UI_WINDOW_H +#define UI_WINDOW_H + +#ifdef _WIN32 + #include + #include + + LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); +#endif + +namespace UI +{ + typedef struct { + unsigned int width = 0; + unsigned int height = 0; + + #ifdef _WIN32 + HWND hwnd; + #endif + } window; + + void window_open(window* w) + { + #ifdef _WIN32 + ShowWindow(w->hwnd, SW_SHOW); + #endif + } + + #ifdef _WIN32 + void window_create_directx(window* w) + { + HINSTANCE hinstance = GetModuleHandle(nullptr); + + WNDCLASSEX wc; + ZeroMemory(&wc, sizeof(WNDCLASSEX)); + + wc.cbSize = sizeof(WNDCLASSEX); + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = WindowProc; + wc.hInstance = hinstance; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH)COLOR_WINDOW; + wc.lpszClassName = "WindowClass1"; + + RegisterClassEx(&wc); + + RECT wr = {0, 0, 800, 600}; + AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); + + w->hwnd = CreateWindowEx((DWORD) NULL, + wc.lpszClassName, NULL, + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, + wr.right - wr.left, + wr.bottom - wr.top, + NULL, NULL, hinstance, w + ); + } + #endif + + window* window_create(window* w) + { + #ifdef _WIN32 + window_create_directx(w); + #endif + + return w; + } +} + +#endif \ No newline at end of file