Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
SetWindowPos moves a window to a new location. Its physical coordinates, dimensions, and Z-order position (the Z-order determines which windows are on top of others) can be set. The function returns 0 if an error occured or a non-zero value if successful.
Example:
' Move Form1 to the upper-left corner of the screen
' and above any other windows
flags = SWP_NOSIZE Or SWP_DRAWFRAME ' don't resize, but redraw window
' (the cx and cy parameters are ignored because of SWP_NOSIZE)
x = SetWindowPos(Form1.hWnd, HWND_TOPMOST, 0, 0, 0, 0, flags)
Related Call: GetWindowRect
Category: Windows
Back to the index.