diff --git a/app/Properties/Resources.Designer.cs b/app/Properties/Resources.Designer.cs index 4d557b78..c68924a0 100644 --- a/app/Properties/Resources.Designer.cs +++ b/app/Properties/Resources.Designer.cs @@ -111,32 +111,32 @@ namespace GHelper.Properties { } /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// Looks up a localized resource of type System.Drawing.Bitmap. /// - internal static System.Drawing.Icon dot_eco { + internal static System.Drawing.Bitmap dot_eco { get { object obj = ResourceManager.GetObject("dot_eco", resourceCulture); - return ((System.Drawing.Icon)(obj)); + return ((System.Drawing.Bitmap)(obj)); } } /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// Looks up a localized resource of type System.Drawing.Bitmap. /// - internal static System.Drawing.Icon dot_standard { + internal static System.Drawing.Bitmap dot_standard { get { object obj = ResourceManager.GetObject("dot_standard", resourceCulture); - return ((System.Drawing.Icon)(obj)); + return ((System.Drawing.Bitmap)(obj)); } } /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// Looks up a localized resource of type System.Drawing.Bitmap. /// - internal static System.Drawing.Icon dot_ultimate { + internal static System.Drawing.Bitmap dot_ultimate { get { object obj = ResourceManager.GetObject("dot_ultimate", resourceCulture); - return ((System.Drawing.Icon)(obj)); + return ((System.Drawing.Bitmap)(obj)); } } diff --git a/app/Properties/Resources.resx b/app/Properties/Resources.resx index 29c0043f..3242cd04 100644 --- a/app/Properties/Resources.resx +++ b/app/Properties/Resources.resx @@ -293,12 +293,12 @@ ..\Resources\Font.otf;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - ..\Resources\dot-eco.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\dot-eco.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\dot-standard.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\dot-standard.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\dot-ultimate.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\dot-ultimate.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/app/Resources/dot-eco.ico b/app/Resources/dot-eco.ico deleted file mode 100644 index 972ddc27..00000000 Binary files a/app/Resources/dot-eco.ico and /dev/null differ diff --git a/app/Resources/dot-eco.png b/app/Resources/dot-eco.png new file mode 100644 index 00000000..b2947573 Binary files /dev/null and b/app/Resources/dot-eco.png differ diff --git a/app/Resources/dot-standard.ico b/app/Resources/dot-standard.ico deleted file mode 100644 index e3bbfdfb..00000000 Binary files a/app/Resources/dot-standard.ico and /dev/null differ diff --git a/app/Resources/dot-standard.png b/app/Resources/dot-standard.png new file mode 100644 index 00000000..bb9f9582 Binary files /dev/null and b/app/Resources/dot-standard.png differ diff --git a/app/Resources/dot-ultimate.ico b/app/Resources/dot-ultimate.ico deleted file mode 100644 index fd34b088..00000000 Binary files a/app/Resources/dot-ultimate.ico and /dev/null differ diff --git a/app/Resources/dot-ultimate.png b/app/Resources/dot-ultimate.png new file mode 100644 index 00000000..6df369ed Binary files /dev/null and b/app/Resources/dot-ultimate.png differ diff --git a/app/Settings.cs b/app/Settings.cs index 4d547da4..88e9a709 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -1150,13 +1150,6 @@ namespace GHelper }); } - [DllImport("user32.dll", CharSet = CharSet.Auto)] - private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); - - private const uint WM_SETICON = 0x80u; - private const int ICON_SMALL = 0; - private const int ICON_BIG = 1; - public void VisualiseGPUMode(int GPUMode = -1) { ButtonEnabled(buttonOptimized, true); @@ -1164,9 +1157,6 @@ namespace GHelper ButtonEnabled(buttonStandard, true); ButtonEnabled(buttonUltimate, true); - Bitmap? smallBmp = null; - Bitmap? bigBmp = null; - if (GPUMode == -1) GPUMode = AppConfig.Get("gpu_mode"); @@ -1185,23 +1175,13 @@ namespace GHelper buttonOptimized.Activated = GPUAuto; labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUModeEco; Program.trayIcon.Icon = Properties.Resources.eco; - - smallBmp = Properties.Resources.dot_eco.ToBitmap(); - bigBmp = Properties.Resources.eco.ToBitmap(); - - SendMessage(this.Handle, WM_SETICON, ICON_SMALL, smallBmp.GetHicon()); - SendMessage(this.Handle, WM_SETICON, ICON_BIG, bigBmp.GetHicon()); + IconHelper.SetIcon(this, Properties.Resources.dot_eco); break; case AsusACPI.GPUModeUltimate: buttonUltimate.Activated = true; labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUModeUltimate; Program.trayIcon.Icon = Properties.Resources.ultimate; - - smallBmp = Properties.Resources.dot_ultimate.ToBitmap(); - bigBmp = Properties.Resources.ultimate.ToBitmap(); - - SendMessage(this.Handle, WM_SETICON, ICON_SMALL, smallBmp.GetHicon()); - SendMessage(this.Handle, WM_SETICON, ICON_BIG, bigBmp.GetHicon()); + IconHelper.SetIcon(this, Properties.Resources.dot_ultimate); break; default: buttonOptimized.BorderColor = colorStandard; @@ -1209,12 +1189,7 @@ namespace GHelper buttonOptimized.Activated = GPUAuto; labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUModeStandard; Program.trayIcon.Icon = Properties.Resources.standard; - - smallBmp = Properties.Resources.dot_standard.ToBitmap(); - bigBmp = Properties.Resources.standard.ToBitmap(); - - SendMessage(this.Handle, WM_SETICON, ICON_SMALL, smallBmp.GetHicon()); - SendMessage(this.Handle, WM_SETICON, ICON_BIG, bigBmp.GetHicon()); + IconHelper.SetIcon(this, Properties.Resources.dot_standard); break; } diff --git a/app/UI/IconHelper.cs b/app/UI/IconHelper.cs new file mode 100644 index 00000000..4daad6f2 --- /dev/null +++ b/app/UI/IconHelper.cs @@ -0,0 +1,24 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +namespace GHelper.UI +{ + public class IconHelper + { + + [DllImport("user32.dll", CharSet = CharSet.Auto)] + private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); + + private const uint WM_SETICON = 0x80u; + private const int ICON_SMALL = 0; + private const int ICON_BIG = 1; + + + public static void SetIcon(Form form, Bitmap icon) + { + SendMessage(form.Handle, WM_SETICON, ICON_SMALL, icon.GetHicon()); + SendMessage(form.Handle, WM_SETICON, ICON_BIG, Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location)!.Handle); + } + + } +}