GetWindowRect Function

Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT) As Long

GetWindowRect reads the size and position of a window. This information is put into the variable passed as lpRect. The rectangle receives the coordinates of the upper-left and lower-right corners of the window. If the window is past one of the edges of the screen, the values will reflect that (for example, if the left edge of a window is off the screen, the rectangle's .Left property will be negative). The function returns 0 if an error occured, or a non-zero value if successful.

hwnd
The handle of the window to read the position and width of.
lpRect
Variable that receives the coordinates of the upper-left and lower-right corners of the window.

Example:

' Find the width and height of Form1
Dim r As RECT
x = GetWindowRect(Form1.hWnd, r)
Debug.Print "Width ="; r.Right - r.Left
Debug.Print "Height ="; r.Bottom - r.Top

Related Call: SetWindowPos
Category: Windows
Back to the index.


Back to Paul Kuliniewicz's Home Page
E-mail: Borg953@aol.com
This page is at http://members.aol.com/Borg953/api/functions/getwindowrect.html