/// <summary>Fills Programs with all currently visible windows</summary> public void PopulateFromWindows() { Programs.Clear(); if (!Windows.EnumDesktopWindows(IntPtr.Zero, EnumWindowsIntoProgramsList, IntPtr.Zero)) { throw new UserException("[SAW_Desktop_Failed]", true); } }
/// <summary>Returns the first visible window for the process or IntPtr.Zero if none, with optional error message in out param </summary> public static IntPtr FindWindowForProcess(IntPtr processID, out string errorMessage) { errorMessage = null; g_FoundHWND = IntPtr.Zero; if (!Windows.EnumDesktopWindows(IntPtr.Zero, EnumWindowsFindForProcess, processID)) { errorMessage = $"FindWindowForProcess failed with code {Marshal.GetLastWin32Error()}."; } return(g_FoundHWND); }