Red Gate forums :: View topic - Hidden controls with enumchildwindows
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
PInvoke.Net
PInvoke.Net forum

Hidden controls with enumchildwindows

Search in PInvoke.Net forum
Post new topic   Reply to topic
Jump to:  
Author Message
kasmajus



Joined: 08 Mar 2010
Posts: 1

PostPosted: Mon Mar 08, 2010 11:43 am    Post subject: Hidden controls with enumchildwindows Reply with quote

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);
Console.ReadLine();
}

static bool delegateenum(IntPtr hwnd, int param)
{
StringBuilder bld = new StringBuilder(1000);
GetWindowText(hwnd, bld, 1000);
string text = bld.ToString();
Console.WriteLine(text);
return true;
}
Back to top
View user's profile Send private message
Paul.Martin



Joined: 03 Feb 2010
Posts: 83
Location: Cambridgeshire

PostPosted: Tue Mar 09, 2010 3:17 pm    Post subject: Reply with quote

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

So you will want something like:

Code:

/// <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;

[DllImport("user32.Dll")]
[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);

[DllImport("user32.dll")]
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.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group