使用Win32 API EnumWindows(如果需要子窗口EnumChildWindows),或者可以使用EnumThreadWindows。
[Dllimport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]public static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);然后通过使用Win32 API GetWindowThreadProcessId检查每个窗口属于哪个进程
[Dllimport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]public static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);


