GetWindow Function

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

Platforms: Win 32s, Win 95/98, Win NT

GetWindow returns the handle of a window related to a given window. The relations generally deal with child-parent relationships or relationships among 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
Exactly one of the following flags specifying which relationship the returned window has to the given window:
GW_HWNDFIRST = 0
The highest window in the Z-order having the same parent as the given window.
GW_HWNDLAST = 1
The lowest window in the Z-order having the same parent as the given window.
GW_HWNDNEXT = 2
The window below the given window in the Z-order.
GW_HWNDPREV = 3
The window above the given window in the Z-order.
GW_OWNER = 4
The window that owns the given window (not to be confused with the parent window).
GW_CHILD = 5
The topmost of the given window's child windows. This has the same effect as using the GetTopWindow function.

Example:

' Flash the application's window that is below Form1 in the Z-order
' once.
Dim next As Long  ' receives handle of next window in the Z-order
Dim retval As Long  ' return value for flashing the window

next = GetWindow(Form1.hWnd, GW_HWNDNEXT)  ' get the handle of the next window
If next <> 0 Then  ' don't try to flags if no such window exists
  ' The next three lines flags the window once.
  retval = FlashWindow(next, 1): Sleep 250
  retval = FlashWindow(next, 1): Sleep 250
  retval = FlashWindow(next, 0)
End If

See Also: GetActiveWindow, GetTopWindow
Category: Windows

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getwindow.html