Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions src/platform/win/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Expand Down
13 changes: 13 additions & 0 deletions src/wrappers/win32/user32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<c_void>);

impl LibraryModule {
Expand Down
3 changes: 2 additions & 1 deletion src/wrappers/win32/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,7 +52,7 @@ pub trait WindowImpl: 'static {
/// [`WindowImpl::after_create`] instead.
pub fn create_window<W: WindowImpl>(
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<HWND> {
let instance = HInstance::get();
let window_class = RegisteredClass::register_new(instance, Some(wnd_proc::<W>))?;
Expand Down