From 82da3e353b1abb1230a9580be2533b5171411912 Mon Sep 17 00:00:00 2001 From: Charles Milette Date: Sun, 29 Apr 2018 11:11:44 -0400 Subject: [PATCH] Change the hand cursor only when we actually open a form --- ShareX/Program.cs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ShareX/Program.cs b/ShareX/Program.cs index 9daeb1ffa..6831feaf1 100644 --- a/ShareX/Program.cs +++ b/ShareX/Program.cs @@ -237,13 +237,6 @@ private static void Main(string[] args) CLI = new CLIManager(args); CLI.ParseCommands(); - // Fix the hand cursor before we open any form. - try - { - FixHandCursor(); - } - catch (Exception) { } // If it fails, we'll just have to live with the old hand. - #if STEAM if (CheckUninstall()) return; // Steam will run ShareX with -Uninstall when uninstalling #endif @@ -298,6 +291,7 @@ private static void Run() LanguageHelper.ChangeLanguage(Settings.Language); + TryFixHandCursor(); DebugHelper.WriteLine("MainForm init started."); MainForm = new MainForm(); DebugHelper.WriteLine("MainForm init finished."); @@ -510,6 +504,7 @@ private static bool CheckAdminTasks() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + TryFixHandCursor(); Application.Run(new DNSChangerForm()); return true; } @@ -591,11 +586,15 @@ private static void CleanTempFiles() }).Start(); } - private static void FixHandCursor() + private static void TryFixHandCursor() { - // https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Cursors.cs,423 - typeof(Cursors).GetField("hand", BindingFlags.NonPublic | BindingFlags.Static) - ?.SetValue(null, new Cursor(NativeMethods.LoadCursor(IntPtr.Zero, NativeConstants.IDC_HAND))); + try + { + // https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Cursors.cs,423 + typeof(Cursors).GetField("hand", BindingFlags.NonPublic | BindingFlags.Static) + ?.SetValue(null, new Cursor(NativeMethods.LoadCursor(IntPtr.Zero, NativeConstants.IDC_HAND))); + } + catch { } // If it fails, we'll just have to live with the old hand. } } } \ No newline at end of file