GetWindowRect Function
Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT) As Long
Platforms: Win 32s, Win 95/98, Win NT
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 1 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:
' Display the width and height of window Form1
' Width and height can be calculated from the coordinates returned in the rectangle.
Dim r As RECT ' receives window rectangle
Dim retval As Long ' return value
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
retval = GetWindowRect(Form1.hWnd, r) ' set r equal to Form1's rectangle
Debug.Print "Width ="; r.Right - r.Left
Debug.Print "Height ="; r.Bottom - r.Top
No comments:
Post a Comment