Skip to content

Commit

Permalink
Re-init if invalid window handle on hide/show
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCakeIsNaOH committed Mar 21, 2021
1 parent a61338a commit 16d93a5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions HideVolumeOSD/HideVolumeOSDLib.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -126,6 +134,11 @@ public void HideOSD()

public void ShowOSD()
{
if (!IsWindow(hWndInject))
{
Init();
}

ShowWindow(hWndInject, 9); // SW_RESTORE

// show window on the screen
Expand Down

0 comments on commit 16d93a5

Please sign in to comment.