From 308a8cd5d353e6493feed1739b12a38f9240f93a Mon Sep 17 00:00:00 2001 From: Cort <1944792+cdwfs@users.noreply.github.com> Date: Sat, 20 Oct 2018 22:46:12 -0700 Subject: [PATCH] Workaround for #1335 (glfwCreateWindow crash) GetDpiForWindow() doesn't exist prior to Win10, so this falls back on the previous behavior (USER_DEFAULT_SCREEN_DPI) if GetDpiForWindow isn't available & avoids the crash. Feel free to edit/replace with a proper fix! --- src/win32_window.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 858931bca..cd3d12fdb 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -210,10 +210,12 @@ static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area) { int xoff, yoff; const float ratio = (float) window->numer / (float) window->denom; + UINT dpi = _glfwIsWindows10AnniversaryUpdateOrGreaterWin32() + ? GetDpiForWindow(window->win32.handle) + : USER_DEFAULT_SCREEN_DPI; getFullWindowSize(getWindowStyle(window), getWindowExStyle(window), - 0, 0, &xoff, &yoff, - GetDpiForWindow(window->win32.handle)); + 0, 0, &xoff, &yoff, dpi); if (edge == WMSZ_LEFT || edge == WMSZ_BOTTOMLEFT || edge == WMSZ_RIGHT || edge == WMSZ_BOTTOMRIGHT) @@ -1002,13 +1004,15 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, { int xoff, yoff; MINMAXINFO* mmi = (MINMAXINFO*) lParam; + UINT dpi = _glfwIsWindows10AnniversaryUpdateOrGreaterWin32() + ? GetDpiForWindow(window->win32.handle) + : USER_DEFAULT_SCREEN_DPI; if (window->monitor) break; getFullWindowSize(getWindowStyle(window), getWindowExStyle(window), - 0, 0, &xoff, &yoff, - GetDpiForWindow(window->win32.handle)); + 0, 0, &xoff, &yoff, dpi); if (window->minwidth != GLFW_DONT_CARE && window->minheight != GLFW_DONT_CARE) @@ -2186,3 +2190,4 @@ GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle) return window->win32.handle; } +