Link to home
Create AccountLog in
Avatar of akjells
akjells

asked on

I want to get a list with all active window handles

Hi
How do i get a list with all active window handles and can i get the window handles by a name i give to match the window caption of all the active windows?
And then
If im intressted in a child window can i get a specific child window caption by search from a name i give?

If you have some samples it would be great with some syntax im not so good at this.
Avatar of josgood
josgood
Flag of United States of America image

One way to locate a window by its caption is to use the Win32 API FindWindowEx.

Here is an example.

using System.Net;
using System.Runtime.InteropServices;

namespace QuickSharpConsole {

   class Program {

      [DllImport("user32", EntryPoint="FindWindowExA")]          
      public static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2);

      static void Main(string[] args) {
         int hWnd = FindWindowEx(0,0,null,"Untitled - Notepad");
      }
   }
}
I forgot to mention that the example assumes you've opened a new Notepad.  That's the window that it will find.
ASKER CERTIFIED SOLUTION
Avatar of josgood
josgood
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of akjells
akjells

ASKER

Thanks for you suggestions.

This is the information i want from my program.
I have a few windows and those windows have these titles.
"Table  3964481 - NL  Hold'em-  $0.25/$0.50.  Good Luck  NAME  !"
where name can be diffrent names.

In these windows there is a static label
The window caption in these labels look like this.
"This Hand# 2,165,412,187"  

I want program a few things in my program around a specific hand and then be able to know what hand "This Hand# 2,165,412,187" belongs to what window "Table  3964481 - NL  Hold'em-  $0.25/$0.50.  Good Luck  NAME  !".

Soory for my stupid questions but im not so good at window handles.

     
You can look thro System.Diagnositcs.Process class

This class has most of the function available as static function to list of process, search by name, getting child controls