diff --git a/src/platform/win/window.rs b/src/platform/win/window.rs index 4316a856..f7c45712 100644 --- a/src/platform/win/window.rs +++ b/src/platform/win/window.rs @@ -631,36 +631,38 @@ impl Window<'_> { let rect = dpi_ctx.client_area_to_nc_area(window_size.into(), style, Dpi::default()).unwrap(); - drop(dpi_ctx); - let is_open = Rc::new(Cell::new(true)); - let parent_handle = ParentHandle { is_open: is_open.clone() }; - - let initializer = move |hwnd: HWnd| { - let window_state = Rc::new(WindowState::new( - hwnd.as_raw(), - window_size, - options.scale, - extended_user_32, - )); - - BaseviewWindow { - window_state, - initial_size: options.size, - handler_builder: Cell::new(Some(Box::new(|w| Box::new(build(w))))), - - _parent_handle: parent_handle, - _drop_target: None.into(), - _keyboard_hook: None.into(), - - #[cfg(feature = "opengl")] - gl_config: options.gl_config, + let initializer = { + let parent_handle = ParentHandle { is_open: is_open.clone() }; + let extended_user_32 = extended_user_32.clone(); + + move |hwnd: HWnd| { + let window_state = Rc::new(WindowState::new( + hwnd.as_raw(), + window_size, + options.scale, + extended_user_32, + )); + + BaseviewWindow { + window_state, + initial_size: options.size, + handler_builder: Cell::new(Some(Box::new(|w| Box::new(build(w))))), + + _parent_handle: parent_handle, + _drop_target: None.into(), + _keyboard_hook: None.into(), + + #[cfg(feature = "opengl")] + gl_config: options.gl_config, + } } }; let hwnd = - create_window(&title, style, rect.size(), parent as *mut _, initializer).unwrap(); + create_window(&title, style, rect.size(), parent as *mut _, &dpi_ctx, initializer) + .unwrap(); // SAFETY: this handle should be safe to use let window = unsafe { HWnd::from_raw(hwnd) }; diff --git a/src/wrappers/win32/user32.rs b/src/wrappers/win32/user32.rs index f42ef4f8..aaf7fdd3 100644 --- a/src/wrappers/win32/user32.rs +++ b/src/wrappers/win32/user32.rs @@ -49,6 +49,19 @@ impl ExtendedUser32 { } } +impl Clone for ExtendedUser32 { + fn clone(&self) -> Self { + let library = unsafe { LibraryModule::load(s!("user32.dll")).unwrap() }; + Self { + _library: library, + + set_thread_dpi_awareness_context: self.set_thread_dpi_awareness_context, + adjust_window_rect_ex_for_dpi: self.adjust_window_rect_ex_for_dpi, + get_dpi_for_window: self.get_dpi_for_window, + } + } +} + struct LibraryModule(NonNull); impl LibraryModule { diff --git a/src/wrappers/win32/window.rs b/src/wrappers/win32/window.rs index ad62e3c2..a3b9af6c 100644 --- a/src/wrappers/win32/window.rs +++ b/src/wrappers/win32/window.rs @@ -13,6 +13,7 @@ use windows_core::{Error, Result, HSTRING}; use crate::wrappers::win32::h_instance::HInstance; use crate::wrappers::win32::style::WindowStyle; +use crate::wrappers::win32::DpiAwarenessContext; use crate::PhySize; use windows_sys::Win32::Foundation::{HWND, LPARAM, LRESULT, WPARAM}; use windows_sys::Win32::UI::WindowsAndMessaging::CreateWindowExW; @@ -51,7 +52,7 @@ pub trait WindowImpl: 'static { /// [`WindowImpl::after_create`] instead. pub fn create_window( title: &HSTRING, style: WindowStyle, nc_size: PhySize, parent: HWND, - initializer: impl FnOnce(HWnd) -> W + 'static, + _dpi_ctx: &DpiAwarenessContext, initializer: impl FnOnce(HWnd) -> W + 'static, ) -> Result { let instance = HInstance::get(); let window_class = RegisteredClass::register_new(instance, Some(wnd_proc::))?;