From def699d3f4518061729a306de24f528baa137a9b Mon Sep 17 00:00:00 2001 From: smigy22 Date: Tue, 28 Feb 2023 20:30:01 +0100 Subject: [PATCH 1/2] - fix - Doesn't work properly in "Silent mode" (command line arguments) --- HideVolumeOSD/HideVolumeOSDLib.cs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/HideVolumeOSD/HideVolumeOSDLib.cs b/HideVolumeOSD/HideVolumeOSDLib.cs index a0e0fe6..e83fd2e 100644 --- a/HideVolumeOSD/HideVolumeOSDLib.cs +++ b/HideVolumeOSD/HideVolumeOSDLib.cs @@ -71,7 +71,7 @@ private struct RECT IntPtr hWndInject = IntPtr.Zero; - VolumePoup volumePopup = new VolumePoup(); + VolumePoup volumePopup; System.Windows.Forms.Timer hideTimer = new System.Windows.Forms.Timer(); @@ -110,10 +110,12 @@ public void Init() return; } - Application.ApplicationExit += Application_ApplicationExit; - if (notifyIcon != null) { + volumePopup = new VolumePoup(); + + Application.ApplicationExit += Application_ApplicationExit; + if (Settings.Default.HideOSD) HideOSD(); else @@ -134,14 +136,14 @@ public void Init() }; notifyIconIdentifier.cbSize = (uint)Marshal.SizeOf(notifyIconIdentifier); - } - KeyHook.VolumeKeyPressed += KeyHook_VolumeKeyPressed; - KeyHook.VolumeKeyReleased += KeyHook_VolumeKeyReleased; + KeyHook.VolumeKeyPressed += KeyHook_VolumeKeyPressed; + KeyHook.VolumeKeyReleased += KeyHook_VolumeKeyReleased; - KeyHook.StartListening(); + KeyHook.StartListening(); - hideTimer.Tick += HideTimer_Tick; + hideTimer.Tick += HideTimer_Tick; + } } private IntPtr FindOSDWindow(bool bSilent) @@ -297,12 +299,15 @@ public void ShowOSD() ShowWindow(hWndInject, 9); // SW_RESTORE - // show window on the screen - internalShowOSD(); - if (notifyIcon != null) + { + // show window on the screen + + internalShowOSD(); + notifyIcon.Icon = Resources.Icon; + } } public void ShowMessage(String message, ToolTipIcon icon) From d6b50ea463e26407de64be50ba35dfdee70834ef Mon Sep 17 00:00:00 2001 From: smigy22 Date: Sun, 9 Apr 2023 09:30:53 +0200 Subject: [PATCH 2/2] fix - application crash on exit in silent mode --- HideVolumeOSD/HideVolumeOSDLib.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/HideVolumeOSD/HideVolumeOSDLib.cs b/HideVolumeOSD/HideVolumeOSDLib.cs index e83fd2e..d22be5c 100644 --- a/HideVolumeOSD/HideVolumeOSDLib.cs +++ b/HideVolumeOSD/HideVolumeOSDLib.cs @@ -110,12 +110,13 @@ public void Init() return; } + if (notifyIcon != null) { - volumePopup = new VolumePoup(); - Application.ApplicationExit += Application_ApplicationExit; + volumePopup = new VolumePoup(); + if (Settings.Default.HideOSD) HideOSD(); else @@ -259,6 +260,9 @@ public void HideOSD() private void internalShowOSD(bool init = false) { + if (notifyIcon == null) + return; + float volume = volumePopup.getVolume(); hideTimer.Stop(); @@ -299,19 +303,19 @@ public void ShowOSD() ShowWindow(hWndInject, 9); // SW_RESTORE + // show window on the screen + internalShowOSD(); + if (notifyIcon != null) - { - // show window on the screen - - internalShowOSD(); - notifyIcon.Icon = Resources.Icon; - } } public void ShowMessage(String message, ToolTipIcon icon) { + if (notifyIcon == null) + return; + notifyIcon.ShowBalloonTip(5000, "HideVolumeOSD", message, icon); long tickCountEnd = Environment.TickCount + 5000;