Function: returns the size of the border rectangle of the specified window. This dimension is given relative to the screen coordinate in the upper left corner of the screen coordinate.
Function prototype: BOOL GetWindowRect (HWND hWnd, LPRECTlpRect );
Parameters:
HWnd: Window handle.
LpRect: a pointer to a RECT structure that receives screen coordinates in the upper left and lower right corner of the window.
Return Value: If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To obtain more error information, call the GetLastError function.
Use this function in C # To first import the namespace:
Copy codeThe Code is as follows:
Using System. Runtime. InteropServices;
Then write the code of the API reference and put it into the class.
Copy codeThe Code is as follows:
[DllImport ("user32.dll")]
Private static extern int GetWindowRect (IntPtr hwnd, out Rect lpRect );
This function has two parameters. The first parameter specifies the window handle. The second parameter receives the screen coordinates in the upper left corner and lower right corner of the window, which is a Rect structure. The Rect structure is defined as follows:
Copy codeThe Code is as follows:
Public struct Rect
{
Public int Left;
Public int Top;
Public int Right;
Public int Bottom;
}
DEMO code:
IntPtr hwnd = FindWindow ("", "Calculator ");
Rect rect = new Rect ();
GetWindowRect (hwnd, out lpRect );