1
1
use super :: { Display , Target } ;
2
+ use windows:: Win32 :: Graphics :: Dwm :: { DwmGetWindowAttribute , DWMWA_EXTENDED_FRAME_BOUNDS } ;
2
3
use windows:: Win32 :: UI :: HiDpi :: { GetDpiForMonitor , GetDpiForWindow , MDT_EFFECTIVE_DPI } ;
4
+ use windows:: Win32 :: UI :: WindowsAndMessaging :: GetWindowRect ;
3
5
use windows:: Win32 :: {
4
6
Foundation :: { HWND , RECT } ,
5
7
Graphics :: Gdi :: HMONITOR ,
@@ -87,7 +89,20 @@ pub fn get_target_dimensions(target: &Target) -> (u64, u64) {
87
89
88
90
// get width and height of the window
89
91
let mut rect = RECT :: default ( ) ;
90
- let _ = windows:: Win32 :: UI :: WindowsAndMessaging :: GetWindowRect ( hwnd, & mut rect) ;
92
+
93
+ // Try DwmGetWindowAttribute first for accurate bounds without shadows
94
+ let result = DwmGetWindowAttribute (
95
+ hwnd,
96
+ DWMWA_EXTENDED_FRAME_BOUNDS ,
97
+ & mut rect as * mut RECT as * mut _ ,
98
+ std:: mem:: size_of :: < RECT > ( ) as u32 ,
99
+ ) ;
100
+
101
+ // Fall back to GetWindowRect if DwmGetWindowAttribute fails
102
+ if result. is_err ( ) {
103
+ let _ = GetWindowRect ( hwnd, & mut rect) ;
104
+ }
105
+
91
106
let width = rect. right - rect. left ;
92
107
let height = rect. bottom - rect. top ;
93
108
@@ -97,8 +112,8 @@ pub fn get_target_dimensions(target: &Target) -> (u64, u64) {
97
112
let monitor = Monitor :: from_raw_hmonitor ( display. raw_handle . 0 ) ;
98
113
99
114
(
100
- monitor. width ( ) . unwrap ( ) as u64 ,
101
- monitor. height ( ) . unwrap ( ) as u64 ,
115
+ monitor. width ( ) . unwrap_or_default ( ) as u64 ,
116
+ monitor. height ( ) . unwrap_or_default ( ) as u64 ,
102
117
)
103
118
}
104
119
}
0 commit comments