function function: This function returns the size of the bounding rectangle for the specified window. The dimension is given in relation to the screen coordinates in the upper-left corner of the screen coordinates.
Function prototype: BOOL GetWindowRect (HWND hwnd,lprectlprect);
Parameters:
HWnd: Window handle.
Lprect: A pointer to a RECT structure that receives the screen coordinates of the upper-left and lower-right corners of the window.
Return value: If the function succeeds, the return value is non 0: If the function fails, the return value is zero. To get more error messages, call the GetLastError function.
Use this function to import namespaces first in C #:
Copy Code code as follows:
Using System.Runtime.InteropServices;
Then write the code for the API Reference section and put it inside the class
Copy Code code as follows:
[DllImport ("user32.dll")]
private static extern int GetWindowRect (IntPtr hwnd,out Rect lprect);
The function has two parameters, the first parameter is the specified window handle, and the second parameter receives the screen coordinates of the upper-left and lower-right corners of the window, which is the RECT structure. The RECT structure is defined as follows:
Copy Code code 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);