From 733488b9de27048a37dbd10800b246c1f04205ad Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sat, 7 Jan 2023 11:58:54 +0800 Subject: [PATCH] Add Windows compatibility Add WNDCLASS parameter to create window method. --- src/main.c | 44 ++++++++++++++++++++++++++++++++++++-------- src/main.h | 1 + 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index 8e55abd..cdb4dce 100644 --- a/src/main.c +++ b/src/main.c @@ -6,11 +6,26 @@ LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); -int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - PWSTR pCmdLine, int nCmdShow) { - LPCWSTR windowName = L"Window"; - MSG msg; +void* CBR_CreateWindow(CBR_CreateWindowParams params) { HWND hwnd; + WNDCLASSW wc = *(WNDCLASSW*)params.params; + RegisterClassW(params.params); + LPWSTR title; + MultiByteToWideChar(CP_UTF8, 0, params.title, -1, title, 0); + hwnd = CreateWindowW( + wc.lpszClassName, + title, // TODO fix + WS_OVERLAPPEDWINDOW | WS_VISIBLE, + params.rect.x, params.rect.y, params.rect.width, params.rect.height, + NULL, NULL, + wc.hInstance, + NULL + ); + + return hwnd; +} + +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { WNDCLASSW wc = { .style = CS_HREDRAW | CS_VREDRAW, .cbClsExtra = 0, @@ -24,14 +39,27 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, .hIcon = LoadIcon(NULL, IDI_APPLICATION), }; - RegisterClassW(&wc); - hwnd = CreateWindowW(wc.lpszClassName, windowName, - WS_OVERLAPPEDWINDOW | WS_VISIBLE, - WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL); + HWND hwnd = CBR_CreateWindow((CBR_CreateWindowParams){ + .rect = (CBR_Rect){ + WINDOW_X, + WINDOW_Y, + WINDOW_WIDTH, + WINDOW_HEIGHT + }, + .style_flags = + CBR_WINDOW_STYLE_FLAG_TITLED + | CBR_WINDOW_STYLE_FLAG_CLOSABLE + | CBR_WINDOW_STYLE_FLAG_MINIATURIZABLE + | CBR_WINDOW_STYLE_FLAG_RESIZABLE, + .title = "Window Title", + .params = &wc + }); ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); + MSG msg; + while (GetMessage(&msg, NULL, 0, 0)) { DispatchMessage(&msg); } diff --git a/src/main.h b/src/main.h index 428d58e..a170b2b 100644 --- a/src/main.h +++ b/src/main.h @@ -26,6 +26,7 @@ typedef struct { CBR_Rect rect; CBR_WindowStyleFlag style_flags; const char* title; + void* params; } CBR_CreateWindowParams; void* CBR_CreateWindow(CBR_CreateWindowParams);