Introduction to C # GetWindowRect and instructions for use _ Practical tips

Source: Internet
Author: User
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);

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.