From 27fa5fc1611fa8d414efb777c846fe0bf3bb8093 Mon Sep 17 00:00:00 2001 From: glowcoil Date: Thu, 5 Oct 2023 10:25:37 -0500 Subject: [PATCH] win32: call EnableNonClientDpiScaling from WM_NCCREATE --- src/backend/win32/window.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/backend/win32/window.rs b/src/backend/win32/window.rs index 945c4d9..3d8ae51 100644 --- a/src/backend/win32/window.rs +++ b/src/backend/win32/window.rs @@ -13,7 +13,7 @@ use windows::Win32::UI::Input::KeyboardAndMouse::{ReleaseCapture, SetCapture}; use windows::Win32::UI::WindowsAndMessaging::{ self as msg, AdjustWindowRectEx, CreateWindowExW, DefWindowProcW, DestroyWindow, GetClientRect, GetWindowLongPtrW, LoadCursorW, RegisterClassW, SetCursor, SetCursorPos, SetWindowLongPtrW, - ShowWindow, UnregisterClassW, HCURSOR, HICON, HMENU, WINDOW_EX_STYLE, WNDCLASSW, + ShowWindow, UnregisterClassW, CREATESTRUCTW, HCURSOR, HICON, HMENU, WINDOW_EX_STYLE, WNDCLASSW, }; use super::app::{AppContextInner, AppState}; @@ -87,6 +87,18 @@ pub unsafe extern "system" fn wnd_proc( wparam: WPARAM, lparam: LPARAM, ) -> LRESULT { + if msg == msg::WM_NCCREATE { + let create_struct = &*(lparam.0 as *const CREATESTRUCTW); + let app_state = &*(create_struct.lpCreateParams as *const AppState); + + #[allow(non_snake_case)] + if let Some(EnableNonClientDpiScaling) = app_state.dpi.EnableNonClientDpiScaling { + EnableNonClientDpiScaling(hwnd); + } + + return DefWindowProcW(hwnd, msg, wparam, lparam); + } + let state_ptr = GetWindowLongPtrW(hwnd, msg::GWLP_USERDATA) as *const WindowState; if !state_ptr.is_null() { // Hold a reference to the WindowState for the duration of the wnd_proc, in case the @@ -351,7 +363,7 @@ impl WindowInner { parent, HMENU(0), hinstance(), - None, + Some(Rc::as_ptr(cx.inner.state) as *const c_void), ); if hwnd == HWND(0) { return Err(windows::core::Error::from_win32().into());