/// <summary> /// steveadoo32: I'd like to get rid of this method eventually. there was a big change /// while i was working on the new stuff so I'm keeping this for now. /// </summary> /// <param name="process"></param> /// <returns></returns> public static IntPtr GetMainWindowForProcess(Process process) { if (Utilities.AppEnvironment.SettingValue("SlowWindowDetection", false)) { try { IntPtr hMainWindow = IntPtr.Zero; lock (Native.GetMainWindowForProcess_Locker) { Native.GetMainWindowForProcess_Value = IntPtr.Zero; // Help the UI stay alive Utilities.Tools.StartMethodMultithreadedAndWait(() => { for (uint i = 0; i <= 1; i++) { foreach (ProcessThread thread in process.Threads) { if (Native.GetMainWindowForProcess_Value != IntPtr.Zero) { break; } Native.EnumThreadWindows(thread.Id, Native.GetMainWindowForProcess_EnumWindows, i); } } }); hMainWindow = Native.GetMainWindowForProcess_Value; } if (hMainWindow != IntPtr.Zero) { return(hMainWindow); } } catch { } } try { // Failsafe //process.Refresh(); return(process.MainWindowHandle); } catch { } return(IntPtr.Zero); }