1

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?

Joan Venge
  • 315,713
  • 212
  • 479
  • 689

3 Answers3

2

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
  • 102,548
  • 21
  • 159
  • 201
  • 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 Jun 19 '09 at 20:49
1

Have you tried to use FindWindowEx?

luiscubal
  • 24,773
  • 9
  • 57
  • 83
  • Thanks I was looking at this page: http://pinvoke.net/default.aspx/user32/FindWindowEx.html but looks very complicated. I will see if I can get it to work. – Joan Venge Jun 19 '09 at 20:22
  • 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 Jun 19 '09 at 20:26
  • Thanks, but how do I find the window control names? I just know the name of one control. – Joan Venge Jun 19 '09 at 20:36
  • 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 Jun 20 '09 at 10:47
1

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
  • 6,507
  • 1
  • 38
  • 48