|
12 | 12 | use std::sync::OnceLock;
|
13 | 13 | use wgpu::rwh::{HasWindowHandle, RawWindowHandle};
|
14 | 14 | use windows::Win32::Foundation::*;
|
15 |
| -use windows::Win32::Graphics::{Dwm::*, Gdi::HBRUSH}; |
| 15 | +use windows::Win32::Graphics::Dwm::*; |
| 16 | +use windows::Win32::Graphics::Gdi::*; |
16 | 17 | use windows::Win32::System::LibraryLoader::GetModuleHandleW;
|
17 | 18 | use windows::Win32::UI::Controls::MARGINS;
|
| 19 | +use windows::Win32::UI::HiDpi::*; |
18 | 20 | use windows::Win32::UI::WindowsAndMessaging::*;
|
19 | 21 | use windows::core::PCWSTR;
|
20 | 22 | use winit::window::Window;
|
@@ -173,11 +175,24 @@ unsafe fn ensure_helper_class() {
|
173 | 175 |
|
174 | 176 | // Main window message handler, called on the UI thread for every message the main window receives.
|
175 | 177 | unsafe extern "system" fn main_window_handle_message(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT {
|
176 |
| - if msg == WM_NCCALCSIZE { |
177 |
| - if wparam.0 != 0 { |
178 |
| - // Return 0 to to tell Windows to skip the default non-client area calculation and drawing. |
179 |
| - return LRESULT(0); |
| 178 | + if msg == WM_NCCALCSIZE && wparam.0 != 0 { |
| 179 | + // When maximized, shrink to visible frame so content doesn't extend beyond it. |
| 180 | + if unsafe { IsZoomed(hwnd).as_bool() } { |
| 181 | + let params = unsafe { &mut *(lparam.0 as *mut NCCALCSIZE_PARAMS) }; |
| 182 | + |
| 183 | + let dpi = unsafe { GetDpiForWindow(hwnd) }; |
| 184 | + let size = unsafe { GetSystemMetricsForDpi(SM_CXSIZEFRAME, dpi) }; |
| 185 | + let pad = unsafe { GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi) }; |
| 186 | + let inset = (size + pad) as i32; |
| 187 | + |
| 188 | + params.rgrc[0].left += inset; |
| 189 | + params.rgrc[0].top += inset; |
| 190 | + params.rgrc[0].right -= inset; |
| 191 | + params.rgrc[0].bottom -= inset; |
180 | 192 | }
|
| 193 | + |
| 194 | + // Return 0 to to tell Windows to skip the default non-client area calculation and drawing. |
| 195 | + return LRESULT(0); |
181 | 196 | }
|
182 | 197 |
|
183 | 198 | let Some(handle) = registry::find_by_main(hwnd) else {
|
|
0 commit comments