Hidden controls with enumchildwindows

Announcements and discussion for PInvoke

Hidden controls with enumchildwindows

Postby kasmajus » Mon Mar 08, 2010 10:43 am

Hi everyone,

Can any one help how to show hidden controls with enumchildwindows ?

here is my code in c#:

static void Main(string[] args)

Int32 hwnd = FindWindow(null, "http://win-7t1f22si9ic/Rapports%20Excel/El%20Watan%20du%20832010.pdf - Windows Internet Explorer");
EnumChildWindows((IntPtr)hwnd, delegateenum, 0);

static bool delegateenum(IntPtr hwnd, int param)
StringBuilder bld = new StringBuilder(1000);
GetWindowText(hwnd, bld, 1000);
string text = bld.ToString();
return true;
Posts: 1
Joined: Mon Mar 08, 2010 10:38 am

Postby Paul.Martin » Tue Mar 09, 2010 2:17 pm

The easiest way is to call ShowWindow(...) on the controls of the window.

So you will want something like:

Code: Select all
/// <summary>
/// Delegate for the EnumChildWindows method
/// </summary>
/// <param name="hWnd">Top-level Window handle</param>
/// <param name="parameter">Caller-defined variable if you want to pass parameters</param>
/// <returns>True to continue enumerating, false to stop enumeration.</returns>
public delegate bool EnumWindowProc(IntPtr hWnd, int parameter);

// Constant to specify how to show the control (window)
const int SW_SHOW = 5;

[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumChildWindows(IntPtr parentHandle, EnumWindowProc callback, IntPtr lParam);

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

static void Main(string[] args)
    IntPtr hwnd = FindWindow((string)null, "The caption of the window");

    // If we can not find the window with the correct caption, FindWindow will return the null pointer.
    // Passing null to EnumChildWindows will result in us enumerating all top-level windows
    // rather than child controls.
    if (hwnd != IntPtr.Zero)
        // Create a delegate proc
        EnumWindowProc ewp = new EnumWindowProc(delegateenum);

        EnumChildWindows(hwnd, ewp, IntPtr.Zero);

static bool delegateenum(IntPtr hwnd, int param)
    // Do other stuff

    // Show the control
    ShowWindow(hwnd, SW_SHOW);

    // Return false if you wish to stop the enumeration
    return true;

The only occassional problem is that some programming languages and frameworks have optimisations which mean that hidden controls are not added to the parent window until they are first shown, and so they will not be part of the enumeration. However, the above method should work in most cases.
Posts: 83
Joined: Wed Feb 03, 2010 10:20 am
Location: Cambridgeshire

Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 0 guests