From 45e7e5551e2f8570fd2385bc2ad776b0793953c3 Mon Sep 17 00:00:00 2001 From: Siddiqui Abdul Rahman <109749723+bourbonbourbon@users.noreply.github.com> Date: Tue, 21 Nov 2023 17:15:54 +0530 Subject: [PATCH] setting different icon for taskbar and title bar (#1614) * setting different icon for taskbar and title bar * fixing variables --- app/Settings.Designer.cs | 4 ++-- app/Settings.cs | 33 ++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/Settings.Designer.cs b/app/Settings.Designer.cs index a28fc544..f8a5d71c 100644 --- a/app/Settings.Designer.cs +++ b/app/Settings.Designer.cs @@ -1439,7 +1439,7 @@ namespace GHelper MinimumSize = new Size(822, 71); Name = "SettingsForm"; Padding = new Padding(11); - ShowIcon = false; + ShowIcon = true; StartPosition = FormStartPosition.CenterScreen; Text = "G-Helper"; panelMatrix.ResumeLayout(false); @@ -1574,4 +1574,4 @@ namespace GHelper private RButton buttonFnLock; private RButton buttonBatteryFull; } -} \ No newline at end of file +} diff --git a/app/Settings.cs b/app/Settings.cs index e7114da3..4d547da4 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -13,13 +13,12 @@ using GHelper.UI; using GHelper.USB; using System.Diagnostics; using System.Timers; +using System.Runtime.InteropServices; namespace GHelper { - public partial class SettingsForm : RForm { - ContextMenuStrip contextMenuStrip = new CustomContextMenu(); ToolStripMenuItem menuSilent, menuBalanced, menuTurbo, menuEco, menuStandard, menuUltimate, menuOptimized; @@ -1151,6 +1150,12 @@ 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) { @@ -1159,6 +1164,9 @@ namespace GHelper ButtonEnabled(buttonStandard, true); ButtonEnabled(buttonUltimate, true); + Bitmap? smallBmp = null; + Bitmap? bigBmp = null; + if (GPUMode == -1) GPUMode = AppConfig.Get("gpu_mode"); @@ -1177,13 +1185,23 @@ namespace GHelper buttonOptimized.Activated = GPUAuto; labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUModeEco; Program.trayIcon.Icon = Properties.Resources.eco; - Icon = Properties.Resources.dot_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()); break; case AsusACPI.GPUModeUltimate: buttonUltimate.Activated = true; labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUModeUltimate; Program.trayIcon.Icon = Properties.Resources.ultimate; - Icon = Properties.Resources.dot_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()); break; default: buttonOptimized.BorderColor = colorStandard; @@ -1191,7 +1209,12 @@ namespace GHelper buttonOptimized.Activated = GPUAuto; labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUModeStandard; Program.trayIcon.Icon = Properties.Resources.standard; - Icon = Properties.Resources.dot_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()); break; }