public IntPtr EnumAllWindow(string processName, EnumWindProc proc, object obj) { Process process = GetProcess(processName); if (process == null) { return(IntPtr.Zero); } WindowsAPI.ShowWindow(process.MainWindowHandle, 1); IntPtr enumAllWindowIsSuccess = IntPtr.Zero; EnumWindProc enumAllWindProc = proc; foreach (ProcessThread th in process.Threads) { WindowsAPI.EnumThreadWindows(th.Id, new EnumWindProc((hwnd, lptr) => { if (!enumAllWindProc(hwnd, lptr)) { return(false); } IntPtr intptr = WindowsAPI.EnumChildWindows(hwnd, enumAllWindProc, lptr); return(intptr == IntPtr.Zero); } ), IntPtr.Zero); if (enumAllWindowIsSuccess != IntPtr.Zero) { return(enumAllWindowIsSuccess); } } return(IntPtr.Zero); }
public static extern int EnumChildWindows(IntPtr hWnd, EnumWindProc lpEnumFunc, ref int lParam);
public static extern IntPtr EnumThreadWindows(int dwThreadId, EnumWindProc proc, IntPtr lParam);
public static extern IntPtr EnumChildWindows(IntPtr hWnd, EnumWindProc proc, IntPtr lParam);
public static extern void EnumWindows(EnumWindProc lpEnumFunc, IntPtr lParam);
private static extern int EnumChildWindows(IntPtr hWnd, EnumWindProc lpEnumFunc, ref IntPtr lParam);