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 (see below). The function continues doing so until all child windows have been enumerated, or until the process has been aborted. Along with a window's handle, the function also passes a program-defined value to the callback function. The function returns 1 if completed successfully, or 0 if an error occured.
Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As _
Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Associated Program-Defined Callback Function:
Function EnumChildProc (ByVal hwnd As Long, ByVal lParam As Long) As Long
' program-defined code goes here
A handle to the parent window to enumerate the child windows of.
A handle to the program-defined callback function. Visual Basic users must use the AddressOf operator to determine the
An additional value to pass to the program-defined callback function.
EnumChildProc is a program-defined callback function which EnumChildWindows calls each time it locates a child window.
The callback function can do whatever it wishes with the handle provided -- the implementation is up to the programmer. If the
function returns 0, EnumChildWindows will prematurely cancel the enumeration process. If the function returns a non-zero value,
EnumChildWindows will continue to enumerate windows until all of them have been enumerated. (Note: the program doesn't
have to call this function EnumChildProc, but it is the standard name given to it.)
A handle to the window which EnumChildWindows has just found.
Whatever value was specified for EnumChildWindows's lParam.
Public Function EnumChildProc (ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim slength As Long, wintext As String
Dim retval As Long
Static winnum As Integer
winnum = winnum + 1
slength = GetWindowTextLength(hwnd) + 1
buffer = Space(slength)
retval = GetWindowText(hwnd, buffer, slength)
Debug.Print "Window #"; winnum; " : ";
Debug.Print Left(buffer, slength - 1)
EnumChildProc = 1
Dim retval As Long
retval = EnumChildWindows(MDIForm1.hWnd, AddressOf EnumChildProc, 0)