11 out of 26 rated this helpful - Rate this topic

EnumChildWindows function

Applies to: desktop apps only

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 WINAPI EnumChildWindows(
  __in_opt  HWND hWndParent,
  __in      WNDENUMPROC lpEnumFunc,
  __in      LPARAM lParam
);

Parameters

hWndParent [in, optional]

Type: HWND

A handle to the parent window whose child windows are to be enumerated. If this parameter is NULL, this function is equivalent to EnumWindows.

lpEnumFunc [in]

Type: WNDENUMPROC

A pointer to an application-defined callback function. For more information, see EnumChildProc.

lParam [in]

Type: LPARAM

An application-defined value to be passed to the callback function.

Return value

Type:

Type: BOOL

The return value is not used.

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.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Reference
EnumChildProc
EnumThreadWindows
EnumWindows
GetWindow
Conceptual
Windows

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
how to use ?
http://www.pinvoke.net/default.aspx/user32/enumchildwindows.html $0 $0 private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); $0[DllImport("user32.dll")]$0 $0[return: MarshalAs(UnmanagedType.Bool)] $0 static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam); $0public static List<IntPtr> GetChildWindows(IntPtr parent)$0 {$0 List<IntPtr> result = new List<IntPtr>();$0 GCHandle listHandle = GCHandle.Alloc(result);$0 try$0 {$0 EnumWindowsProc childProc = new EnumWindowsProc(EnumWindow);$0 EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));$0 }$0 finally$0 {$0 if (listHandle.IsAllocated)$0 listHandle.Free();$0 }$0 return result;$0 }$0 $0 $0 private static bool EnumWindow(IntPtr handle, IntPtr pointer)$0 {$0 GCHandle gch = GCHandle.FromIntPtr(pointer);$0 List<IntPtr> list = gch.Target as List<IntPtr>;$0 if (list == null)$0 {$0 throw new InvalidCastException("GCHandle Target could not be cast as List<IntPtr>");$0 }$0 list.Add(handle);$0 // You can modify this to check to see if you want to cancel the operation, then return a null here$0 return true;$0 }$0 $0 Nice work. I just fixed a couple of typos. Thanks. JC$0
Empty "Return Value" section
The section "Return Value" does not say anything about the expected return values and their meaning.
Possible VB9 declaration
Friend Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Int32, ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As Int32) As Boolean

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