Skip to content

Commit

Permalink
win32: call EnableNonClientDpiScaling from WM_NCCREATE
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Oct 5, 2023
1 parent cd6fcd2 commit 27fa5fc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/backend/win32/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 27fa5fc

Please sign in to comment.