From 2e88c971789720d205d21181b59a6631ffea6f09 Mon Sep 17 00:00:00 2001 From: Usman Shafiq Date: Wed, 23 Mar 2022 22:25:08 -0400 Subject: [PATCH] Cleanup of WinformThemer --- WinformThemer.cs | 57 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/WinformThemer.cs b/WinformThemer.cs index 77710e85..fd13f3c6 100644 --- a/WinformThemer.cs +++ b/WinformThemer.cs @@ -29,11 +29,7 @@ namespace VRCX { forms.Add(form); } - - foreach (Form form in forms) - { - SetThemeToGlobal(form); - } + SetThemeToGlobal(forms); } /// @@ -43,27 +39,35 @@ namespace VRCX /// public static int GetGlobalTheme() => currentTheme; + public static void SetThemeToGlobal(Form form) { - SetThemeToGlobal(form.Handle); + SetThemeToGlobal(new List
() { form }); + } - InvisPopup thisJankThing = new InvisPopup(); - thisJankThing.Show(); + public static void SetThemeToGlobal(List forms) + { + InvisPopupHandler.Show(); - if (form.WindowState != FormWindowState.Minimized) + foreach(Form form in forms) { - //attempting to refresh this god forsaken title bar + SetThemeToGlobal(form.Handle); - //Minimize, Downside: shows animation - //PInvokeFun.ShowWindow(form.Handle, (int)PInvokeFun.SW_TYPES.SW_MINIMIZE); - //PInvokeFun.ShowWindow(form.Handle, (int)PInvokeFun.SW_TYPES.SW_RESTORE); + if (form.WindowState != FormWindowState.Minimized) + { + //attempting to refresh this god forsaken title bar - //Hide, Downside: reorders window to last in taskbar if not pinned - PInvokeFun.ShowWindow(form.Handle, (int)PInvokeFun.SW_TYPES.SW_HIDE); - PInvokeFun.ShowWindow(form.Handle, (int)PInvokeFun.SW_TYPES.SW_SHOW); + //Minimize, Downside: shows animation + //PInvokeFun.ShowWindow(form.Handle, (int)PInvokeFun.SW_TYPES.SW_MINIMIZE); + //PInvokeFun.ShowWindow(form.Handle, (int)PInvokeFun.SW_TYPES.SW_RESTORE); + + //Hide, Downside: reorders window to last in taskbar if not pinned + PInvokeFun.ShowWindow(form.Handle, (int)PInvokeFun.SW_TYPES.SW_HIDE); + PInvokeFun.ShowWindow(form.Handle, (int)PInvokeFun.SW_TYPES.SW_SHOW); + } } - thisJankThing.Close(); + InvisPopupHandler.Close(); } private static void SetThemeToGlobal(IntPtr handle) @@ -93,6 +97,25 @@ namespace VRCX return theme; } + internal static class InvisPopupHandler + { + private static InvisPopup instance; + + internal static void Show() + { + if(instance == null) + instance = new InvisPopup(); + instance.Show(); + } + + internal static void Close() + { + instance.Close(); + instance.Dispose(); + instance = null; + } + } + internal static class PInvokeFun { [DllImport("DwmApi")]