Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
EnumChildWindows enumerates and provides handles to all of the child windows of a given window. This function will also enumerate any children of the child windows. Each time a child window is located, the function passes that handle to a program-defined callback function. The function continues doing so until all child windows have been enumerated, or until the process has been aborted.
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a non-zero value.
None.
Example:
' Display the window title of all children of window MDIForm1. This
' task is given to the callback function, which will receive each handle individually.
' *** Place this code in a module. This is the callback function. ***
' This function displays the title bar text of the window identified by hwnd.
Public Function EnumChildProc (ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim slength As Long, wintext As String ' window title text length and buffer
Dim retval As Long ' return value
Static winnum As Integer ' counter keeps track of how many windows have been enumerated
winnum = winnum + 1 ' one more window enumerated....
slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text
buffer = Space(slength) ' make room in the buffer
retval = GetWindowText(hwnd, buffer, slength) ' get title bar text
Debug.Print "Window #"; winnum; " : "; ' display number of enumerated window
Debug.Print Left(buffer, slength - 1) ' display title bar text of enumerated window
EnumChildProc = 1 ' nonzero return value means continue enumeration
End Function
' *** Place this code wherever you want to enumerate the windows. ***
Dim retval As Long ' return value
' Use the above callback function to list all of the enumerated windows. Note that lParam is
' set to 0 because we don't need to pass any additional information to the function.
retval = EnumChildWindows(MDIForm1.hWnd, AddressOf EnumChildProc, 0)
EnumThreadWindows, EnumWindows
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: August 15, 1999
This page is copyright © 1999 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
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/e/enumchildwindows.html