//============ CHECKS ============ #region Checks /**<summary>Updates the info on the Terraria window.</summary>*/ public static bool Update(bool fullUpdate) { try { if (fullUpdate) { process = null; string[] exeNames = Config.ExecutableNames.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < exeNames.Length && process == null; i++) { if (!string.IsNullOrWhiteSpace(exeNames[i])) { process = Process.GetProcessesByName(exeNames[i]).FirstOrDefault(); } } } if (process != null) { clientArea = CppImports.GetClientArea(process.MainWindowHandle); focus = CppImports.WindowHasFocus(process.MainWindowHandle); return(clientArea != new Rect(0, 0, 0, 0)); } } catch (Exception) { } clientArea = new Rect(0, 0, 0, 0); focus = false; return(false); }
//============ CHECKS ============ #region Checks /**<summary>Updates the info on the Terraria window.</summary>*/ public static bool Update(bool fullUpdate) { try { if (fullUpdate) { process = Process.GetProcessesByName(Config.ExecutableName).FirstOrDefault(); } if (process != null) { clientArea = CppImports.GetClientArea(process.MainWindowHandle); focus = CppImports.WindowHasFocus(process.MainWindowHandle); return(clientArea != new Rect(0, 0, 0, 0)); } } catch (Exception) { } clientArea = new Rect(0, 0, 0, 0); focus = false; return(false); }
//https://stackoverflow.com/questions/2315561/correct-way-in-net-to-switch-the-focus-to-another-application?answertab=oldest#tab-top /**<summary>Focuses on the Terraria Window.</summary>*/ public static bool Focus() { try { if (process != null) { // The window is hidden so try to restore it before setting focus. CppImports.RestoreFromMinimzied(process.MainWindowHandle); // Set user the focus to the window CppImports.FocusWindow(process.MainWindowHandle); // Reacquire the client rect clientArea = CppImports.GetClientArea(process.MainWindowHandle); focus = CppImports.WindowHasFocus(process.MainWindowHandle); return(clientArea != new Rect(0, 0, 0, 0)); } return(false); } catch (Exception) { return(false); } }