Despite the fact that you, of course, can use programs that really seem excessive for what you want to do. This code should make you VERY close (you will need to do something else to request the Windows Explorer process for its current directory, I did not). In addition, my needs are different from yours, as mine shows more than just the definition of Window (the popup tooltip is technically a βwindowβ). Explorer.exe, Chrome and Internet Explorer can have several windows for one process, both windows are closed. Depending on your needs, you can see:
List windows e.g. alt-tab
EnumWindows filter for windows displayed on alt-tab only
using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; namespace ConsoleApplication { class Program { static void Main(string[] args) { ProcessListModel processes = Program.GetProccesses(); foreach (ProcessModel process in processes.Items) { Console.WriteLine("Program: " + process.Filename + "[" + process.IsWindowsExplorer.ToString() + "]"); Console.WriteLine("- Window Text: " + process.WindowText); } Console.ReadKey(); } [DllImport("user32")] public static extern int EnumWindows(EnumWindowsDelegate CallBack, ProcessListModel Processes); [DllImport("user32.dll")] private static extern IntPtr GetWindowThreadProcessId(int hWnd, out int lpdwProcessId); [DllImport("user32")] internal static extern int GetAncestor(int hwnd, int gaFlags); [DllImport("user32")] internal static extern int GetLastActivePopup(int hWnd); [DllImport("user32")] internal static extern bool IsWindowVisible(int hWnd); [DllImport("User32.Dll")] public static extern void GetWindowText(int h, StringBuilder s, int nMaxCount); internal delegate bool EnumWindowsDelegate(int Hwnd, ProcessListModel Processes); internal static bool EnumWindowsCallBack(int Hwnd, ProcessListModel Processes) { ProcessModel model = new ProcessModel();
Exit: (I have many open windows, this is just a small list of them)

NOTE This does not list child windows, so if I have Internet Options open in IE and I close it, it will be a child window, not the main window of the process. If you need child windows, you will have to implement the EnumChildWindows function in a similar way.
What you asked for is SO complicated, there is no direct way to do exactly what you want.
source share