Change the hand cursor only when we actually open a form

This commit is contained in:
Charles Milette 2018-04-29 11:11:44 -04:00
parent d8c2a7f796
commit 82da3e353b
No known key found for this signature in database
GPG key ID: 1A5AE81377AD973A

View file

@ -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.
}
}
}