views:

341

answers:

3

Basically I am looking for a win32 method to invoke in C# to set the focus to a children of an unmanaged application.

But first I need to find the child control's handle which is the problem. Any useful win32 functions to solve this?

A: 

Have you tried to use FindWindowEx?

luiscubal
Thanks I was looking at this page:http://pinvoke.net/default.aspx/user32/FindWindowEx.htmlbut looks very complicated. I will see if I can get it to work.
Joan Venge
Use the IntPtr.Zero as previous window argument for the first. Then keep a "Last child" variable and keep using to retrieve the next child window. Then either check for the end of the window list or for the intended window. This could either be in a while or for loop.
luiscubal
Thanks, but how do I find the window control names? I just know the name of one control.
Joan Venge
You'll have to find something that identifies your child. Perhaps class? You say you know the name for one control. Which control exactly?
luiscubal
A: 

There is a library which supports enumerating and searching window handles, which is available at http://mwinapi.sourceforge.net/

Just so that you do not have to reinvent the wheel every time ;)

Start with

SystemWindow.AllToplevelWindows

and then just dig your way down (looking at class names, process names, titles, dialog IDs, whatever).

mihi
+1  A: 

Use FindWindowEx to find the Handle of the Window you're looking for. Once you have that handle, use EnumChildWindows to find the correct child you need. There's too much code involved for me to quickly write up a sample, but there's enough on the web to help.

From Pinvoke.net: http://www.pinvoke.net/default.aspx/user32/EnumChildWindows.html

BFree
Thanks, I looked at the 2nd link, but GetChildWindows don't return the children, returns an empty list. I checked my app handle and it's correct.
Joan Venge