Using user-defined data type variables
The GetWindowRect C function uses a structured type to retrieve the screen coordinates (in pixels) of the specified window. You must use a Type statement to define the structure. GetWindowRect does not have a return value, so you can declare it as a sub. You pass the window handle by value and the user-defined data type variable by reference. The window handle is an input parameter (it identifies the window), and the Rect user-defined data type variable is an output parameter (GetWindowRect sets its values).
This set of declarations also includes MoveWindow, which you can use to move and/or resize the window. This example also uses data type suffix characters to save space in the Declare statements.
Declare Function GetActiveWindow Lib "User32" () As Long
Type Rect
left As Long
top As Long
right As Long
bottom As Long
End Type
Declare Sub GetWindowRect Lib "User32" (Byval hWnd As Long, _
lpRect As Rect)
Declare Sub MoveWindow Lib "User32" _
(Byval hWnd As Long, Byval x As Long, Byval y As Long, _
Byval nWidth As Long, nHeight As Long, Byval bRepaint As Long)
Sub Initialize
Dim activeWin As Long, winRect As Rect
activeWin = GetActiveWindow
Call GetWindowRect(activeWin, winRect)
Call MoveWindow(activeWin, winRect.left, winRect.top, _
winRect.right/2, winRect.bottom/2, True)
End Sub