C # getwindowrect usage

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, 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:

 
UsingSystem. runtime. interopservices;

Then writeCodeIn the class.

[Dllimport ("User32.dll")]Private Static Extern IntGetwindowrect (intptr hwnd,OutRect 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:

 Public   Struct  Rect {  Public   Int  Left;  Public  Int  Top;  Public   Int  Right;  Public   Int  Bottom;} DEMO code: intptr hwnd = Findwindow ( "" , "  Calculator  "  ); Rect = New  Rect (); getwindowrect (hwnd, Out Lprect );

Reprinted from: http://blog.csdn.net/dangdaa/article/details/7001810

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.