diff --git a/HideVolumeOSD/HideVolumeOSDLib.cs b/HideVolumeOSD/HideVolumeOSDLib.cs index f1f2637..9f3125d 100644 --- a/HideVolumeOSD/HideVolumeOSDLib.cs +++ b/HideVolumeOSD/HideVolumeOSDLib.cs @@ -19,6 +19,9 @@ public class HideVolumeOSDLib [DllImport("user32.dll", SetLastError = true)] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); + [DllImport("user32.dll")] + static extern bool IsWindow(IntPtr hWnd); + NotifyIcon ni; IntPtr hWndInject = IntPtr.Zero; @@ -118,6 +121,11 @@ private void Application_ApplicationExit(object sender, EventArgs e) public void HideOSD() { + if (!IsWindow(hWndInject)) + { + Init(); + } + ShowWindow(hWndInject, 6); // SW_MINIMIZE if (ni != null) @@ -126,6 +134,11 @@ public void HideOSD() public void ShowOSD() { + if (!IsWindow(hWndInject)) + { + Init(); + } + ShowWindow(hWndInject, 9); // SW_RESTORE // show window on the screen