private static bool EnumTopWindows(IntPtr hWnd, IntPtr lParam) { int winProcessId = 0; WindowAction.GetWindowThreadProcessId(hWnd, out winProcessId); if (!IsWindow(hWnd) || !WindowAction.IsWindowVisible(hWnd) || hWnd == WindowAction.statusbar ) { return(true); } GCHandle gch = (GCHandle)lParam; ProcessHWinds phw = (ProcessHWinds)(gch.Target); if (!DoesWindowBelongToProcess(hWnd, phw.processId)) { return(true); } phw.topWinds.Add(hWnd); return(true); }
public static IntPtr[] GetTopWindowsForProcess(int processId) { ProcessHWinds phw = new ProcessHWinds(); ArrayList topwinds = new ArrayList(); phw.processId = processId; phw.topWinds = topwinds; GCHandle gch = GCHandle.Alloc(phw); EnumWindowsProc callback = new EnumWindowsProc(EnumTopWindows); EnumWindows(callback, (IntPtr)gch); return((IntPtr[])topwinds.ToArray(typeof(IntPtr))); }