11use super :: { Display , Target } ;
2+ use windows:: Win32 :: Graphics :: Dwm :: { DwmGetWindowAttribute , DWMWA_EXTENDED_FRAME_BOUNDS } ;
23use windows:: Win32 :: UI :: HiDpi :: { GetDpiForMonitor , GetDpiForWindow , MDT_EFFECTIVE_DPI } ;
4+ use windows:: Win32 :: UI :: WindowsAndMessaging :: GetWindowRect ;
35use windows:: Win32 :: {
46 Foundation :: { HWND , RECT } ,
57 Graphics :: Gdi :: HMONITOR ,
@@ -87,7 +89,20 @@ pub fn get_target_dimensions(target: &Target) -> (u64, u64) {
8789
8890 // get width and height of the window
8991 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+
91106 let width = rect. right - rect. left ;
92107 let height = rect. bottom - rect. top ;
93108
@@ -97,8 +112,8 @@ pub fn get_target_dimensions(target: &Target) -> (u64, u64) {
97112 let monitor = Monitor :: from_raw_hmonitor ( display. raw_handle . 0 ) ;
98113
99114 (
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 ,
102117 )
103118 }
104119 }
0 commit comments