1

first time writing a question here, this site helped me a lot thru the years, thanks !

DwmGetWindowAttribute doesn't return exact rectangle where the window is and its's size using this code :

[DllImport("User32.dll")]
public static extern IntPtr GetForegroundWindow();

[DllImport("dwmapi.dll")]
public static extern int DwmGetWindowAttribute(IntPtr hwnd, DwmWindowAttribute dwAttribute, out RECT pvAttribute, int cbAttribute);

Intptr m_current_active_window_handle = GetForegroundWindow();
DwmGetWindowAttribute(m_current_active_window_handle, DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS, out RECT __rv, Marshal.SizeOf(typeof(RECT)));

I want to get capture of active/foreground window at specific occasions and I tested on 2 different versions of windows and still not working with my setup..

Dual 1440p monitors (both 100% scaling)

Windows 10 Enteprise LTSC 2019

Windows 10 Pro (19042)

I have disabled animations during minimizie/maximize, dropshadow under windows

here is what I get and sometimes it returns me window with 2 extra pixels on top and non on the other 3 sides which have black border..

ps. ignore white region around the window, it is purposely there to show extra stuff around 'window':

sample screenshot

Ramil Aliyev 007
  • 4,437
  • 2
  • 31
  • 47
mmx
  • 19
  • 2
  • 5
  • The window rect (GetWindowRect) and the window extended frame bounds (DwmGetWindowAttribute(DWMWA_EXTENDED_FRAME_BOUNDS)) are often but not always identical. see https://learn.microsoft.com/en-us/windows/win32/dwm/customframe and https://stackoverflow.com/questions/32159675/retrieve-window-size-without-windows-shadows . Usually Window Client Rect is included or equal to Extended Frame Bounds which is included or equal to Window Rect. – Simon Mourier Feb 22 '21 at 16:45
  • Yes, I've already compared `GetWindowRect` and `DwmGetWindowAttribute` and the later worked better because it didn't include the window shadow - just returned windows' actual size. – mmx Feb 22 '21 at 19:55

0 Answers0