I am trying to get the height and the width of the current active window.
[DllImport(\"user32.dll\", CharSet = CharSet.Auto, ExactSpelling = true)]
public st
Of course that code will not work. It has to be this way: GetWindowRect(handle, ref rect);
. So, edit your GetWindowRect
declaration. And Rectangle
is just a wrapper of the native RECT
. Rectangle
and RECT
has left, top, right and bottom fields that the Rectangle class changed to read-properties (Left
, Top
, Right
, Bottom
). Width
is not equivalent to right and Height
is not equivalent to bottom. Width
is right-left and Height
is bottom-top. Of course, RECT
don't have these sort of properties. It's just a bare struct.
Creating RECT
is an overkill. Rectangle
is enough in .NET for native/unmanaged API that need it. You just have to pass it in the appropriate way.