From d9c68cd32d40009f9d70954197130a9cdfc0f0a9 Mon Sep 17 00:00:00 2001 From: Philosoph228 Date: Mon, 24 Mar 2025 03:21:19 +0500 Subject: [PATCH] Fix CreateWindow client size CreateWindow(Ex) size parameters actually accepts outer window dimensions containing caption and border, which we can calculate with AdjustWindowRect by giving client size window dimensions. --- examples/win32_gdi/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/win32_gdi/main.c b/examples/win32_gdi/main.c index 761c59e..c28fbd3 100644 --- a/examples/win32_gdi/main.c +++ b/examples/win32_gdi/main.c @@ -26,6 +26,9 @@ void CenterWindow(HWND hWnd); long lastMsgTime = 0; bool ui_debug_mode; +#define RECTWIDTH(rc) ((rc).right - (rc).left) +#define RECTHEIGHT(rc) ((rc).bottom - (rc).top) + LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -165,6 +168,10 @@ int APIENTRY WinMain( if (FALSE == RegisterClass(&wc)) return 0; + // Calculate window rectangle by given client size + // TODO: AdjustWindowRectExForDpi for DPI support + RECT rcWindow = { .right = 800, .bottom = 600 }; + AdjustWindowRect(&rcWindow, WS_OVERLAPPEDWINDOW, FALSE); hwnd = CreateWindow( szAppName, @@ -172,8 +179,8 @@ int APIENTRY WinMain( WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, - 800, // CW_USEDEFAULT, - 600, // CW_USEDEFAULT, + RECTWIDTH(rcWindow), // CW_USEDEFAULT, + RECTHEIGHT(rcWindow), // CW_USEDEFAULT, 0, 0, hInstance,