C # GetWindowRect introduction and instructions for use

Source: Internet
Author: User

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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.