The EnumChildWindows function enumerates the child windows that belong to the specified parent window by passing the handle to each child window, in turn, to an application-defined callback function. EnumChildWindows continues until the last child window is enumerated or the callback function returns FALSE.
Syntax
BOOL EnumChildWindows( HWND hWndParent, WNDENUMPROC lpEnumFunc, LPARAM lParam );
Parameters
hWndParent [in] Handle to the parent window whose child windows are to be enumerated. If this parameter is NULL, this function is equivalent to EnumWindows. Windows 95/98/Me: hWndParent cannot be NULL.lpEnumFunc [in] Pointer to an application-defined callback function. For more information, see EnumChildProc. lParam [in] Specifies an application-defined value to be passed to the callback function.
Windows 95/98/Me: hWndParent cannot be NULL.
Return Value
Remarks
If a child window has created child windows of its own, EnumChildWindows enumerates those windows as well. A child window that is moved or repositioned in the Z order during the enumeration process will be properly enumerated. The function does not enumerate a child window that is destroyed before being enumerated or that is created during the enumeration process.
If a child window has created child windows of its own, EnumChildWindows enumerates those windows as well.
A child window that is moved or repositioned in the Z order during the enumeration process will be properly enumerated. The function does not enumerate a child window that is destroyed before being enumerated or that is created during the enumeration process.
Example
For an example see Destroying a Window.
Function Information
Minimum DLL Versionuser32.dllHeaderDeclared in Winuser.h, include Windows.hImport libraryUser32.libMinimum operating systems Windows 95, Windows NT 3.1UnicodeImplemented as Unicode version.
See Also
Windows Overview, EnumChildProc, EnumThreadWindows, EnumWindows, GetWindow
Friend Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Int32, ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As Int32) As BooleanExample: (this example is part of class that represents Win32 native window) ''' <summary>Adds <paramref name="item"/> to <paramref name="List"/> and returns true</summary> ''' <param name="List"><see cref="List(Of T)"/> to add item to</param> ''' <param name="item">Item to be added</param> ''' <typeparam name="T">Type of <paramref name="item"/></typeparam> ''' <returns>True</returns> Private Shared Function AddToList(Of T)(ByVal List As List(Of T), ByVal item As T) As Boolean List.Add(item) Return True End Function ''' <summary>Gets all childrens of current windows</summary> ''' <returns>Childrens of current window</returns> ''' <exception cref="API.Win32APIException">Error while enumerating windows. Ie. <see cref="Handle"/> is invalid</exception> <Category("Relationship")> _ <TypeConverter(GetType(CollectionConverter))> _ Public ReadOnly Property Children() As IReadOnlyList(Of Win32Window) 'Localize: description Get Dim List As New List(Of Win32Window) If API.EnumChildWindows(hWnd, New API.EnumWindowsProc(Function(hWnd As Integer, lParam As Integer) AddToList(List, New Win32Window(hWnd))), 0) Then Return New ReadOnlyListAdapter(Of Win32Window)(List) Else Dim ex As New API.Win32APIException If ex.NativeErrorCode <> 0 Then Throw ex Else Return New ReadOnlyListAdapter(Of Win32Window)(List) End If End If End Get End Property
Example: (this example is part of class that represents Win32 native window)
''' <summary>Adds <paramref name="item"/> to <paramref name="List"/> and returns true</summary> ''' <param name="List"><see cref="List(Of T)"/> to add item to</param> ''' <param name="item">Item to be added</param> ''' <typeparam name="T">Type of <paramref name="item"/></typeparam> ''' <returns>True</returns> Private Shared Function AddToList(Of T)(ByVal List As List(Of T), ByVal item As T) As Boolean List.Add(item) Return True End Function ''' <summary>Gets all childrens of current windows</summary> ''' <returns>Childrens of current window</returns> ''' <exception cref="API.Win32APIException">Error while enumerating windows. Ie. <see cref="Handle"/> is invalid</exception> <Category("Relationship")> _ <TypeConverter(GetType(CollectionConverter))> _ Public ReadOnly Property Children() As IReadOnlyList(Of Win32Window) 'Localize: description Get Dim List As New List(Of Win32Window) If API.EnumChildWindows(hWnd, New API.EnumWindowsProc(Function(hWnd As Integer, lParam As Integer) AddToList(List, New Win32Window(hWnd))), 0) Then Return New ReadOnlyListAdapter(Of Win32Window)(List) Else Dim ex As New API.Win32APIException If ex.NativeErrorCode <> 0 Then Throw ex Else Return New ReadOnlyListAdapter(Of Win32Window)(List) End If End If End Get End Property