# GetWindow Function

`Declare Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long`

GetWindow returns the handle of a window related to a given window. The relations generally deal with child-parent relationships or relationships between children of the same parent window. The exact relation is specified by wCmd. If an error occurs or there is no window having the specified relation, the function instead returns 0.

hwnd
  The handle of the first window in the relation.
wCmd
  One of the GetWindow flags specifying the relationship between the two windows.

Example:

    ' Flash the window below Form1 in the Z-order once
    next = GetWindow(Form1.hWnd, GW_HWNDNEXT)  ' next window in Z-order
    ' The next three lines flash this window using FlashWindow and Sleep
    x = FlashWindow(next, 1): Sleep 250
    x = FlashWindow(next, 1): Sleep 250
    x = FlashWindow(next, 0)

Related Calls: GetActiveWindow, GetTopWindow
Category: Windows
Back to the index.