0

For example if i got this window (which is not part of this project): Example Is there a way to get the size of this window? (int x and y)

Thanks, Revolt

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
RevoltPlz
  • 215
  • 2
  • 3
  • 10

1 Answers1

1

If you have the HWND of the window then you can use GetWindowRect() or GetWindowPlacement() to get its position and dimensions.

Update: On Vista and later, GetWindowRect() can report values that do not take Glass/Aero into account. To account for that, you can use DwmGetWindowAttribute() with the DWMWA_EXTENDED_FRAME_BOUNDS attribute instead.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I tried that but it gives the wrong size, about 1.5x as big as it is supposed to be, on all kinds of windows (google chrome, skype etc.), how can i solve this/any other ways? – RevoltPlz Apr 25 '14 at 19:51
  • Maybe you are running into this issue: http://stackoverflow.com/questions/3192232/getwindowrect-too-small-on-windows-7/3192264#3192264. See also: http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/6c1c67a9-5548-4e9b-989f-c7dbac0b1375 – Remy Lebeau Apr 26 '14 at 01:23
  • I'm a little confused, what would be the right code then? Because the code in that thread just gives a bunch of errors. EDIT: i tried that DwmGetWindowAttribute but this gives errors aswell, it seems like it does not recognize DWM or the HRESULT in that same part. EDIT2: Just noticed it a second ago: this is a C++ code, got the C# code maybe? – RevoltPlz Apr 26 '14 at 21:30