Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • How to get handle of all the windows which are open ?
AuthorQuestion
How to get handle of all the windows which are open ?
Posted on: 19 Nov 2007
Hi ,
I want to get the handle of all the windows open in the taskbar. I used 'GetForegroundWindow()'. but it shows the handle of the desktop window only.
Does any one can help

Thanks and regards
Anez.A

Anez.A
AuthorReply
Re: How to get handle of all the windows which are open ?
Posted on: 19 Nov 2007  
Hi Guy
Hello, r u try get Handle from the ur applciation opened windows is it? if u say OK,
i can give hint to u. when u oepn every forms please put the Diectory with name, after search with that directory get the form name after create objecvt from the and get the handle and do ur work.

thanks

Best Regards
RRave(MCTS,MCPD,MCP)
http://ravesoft.blogspot.com

Alan
  • 0
  • 0
Re: How to get handle of all the windows which are open ?
Posted on: 19 Nov 2007  

I suspect Anez means not just windows belonging to the current application but any other running application as well.

The following code will get the handle of the main window for every process with a UI (i.e. a non-zero handle) running on the local machine. This isn't quite the same as what you asked for but it may suffice, depending on what you want to do:

using System;
using System.Diagnostics;

class Program
{
    static void Main()
    {
       Process[] procs = Process.GetProcesses();
       IntPtr hWnd;
       foreach(Process proc in procs)
       {
          if ((hWnd = proc.MainWindowHandle) != IntPtr.Zero)
          {
             Console.WriteLine("{0} : {1}", proc.ProcessName, hWnd);
          }
       }        
    }

}


Re: How to get handle of all the windows which are open ?
Posted on: 21 Nov 2007  
thanks frnds..........
now i got the idea......
Once again... thanks a lot.....

Anez.A
Re: How to get handle of all the windows which are open ?
Posted on: 15 Jan 2010  
try this link

http://www.csharphelp.com/2006/08/get-current-window-handle-and-caption-with-windows-api-in-c/

Please check my answer if you help.....

Thanks ....Lalit.

Re: How to get handle of all the windows which are open ?
Posted on: 24 Oct 2011  
Re: How to get handle of all the windows which are open ?
Posted on: 24 Oct 2011  
Please see Automating programs using C#. I have sample code there that uses EnumWindows. You don't need most of that sample, though. You will need:

[DllImport("user32.dll")]
private static extern
int EnumWindows(EnumWindowsProc ewp, int lParam);
public delegate bool EnumWindowsProc(int hWnd, int lParam);

public static bool MyEWP(int hwnd, int lparam)
{
// your processing
return true;
}

Then use it as:

EnumWindowsCB cb = new EnumWindowsCB(MyEWP);
EnumWindows(cb, lParam);

Thinking is a feeling; pleasant for some and unpleasant for others.

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.