Skip to content

Commit

Permalink
Merge pull request #7 from yukimono/patch-2
Browse files Browse the repository at this point in the history
Hide overlay in alt+tab
  • Loading branch information
RainbowMage committed Jan 17, 2015
2 parents 45c3f65 + 8542719 commit 7909f30
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions OverlayPlugin/OverlayForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public OverlayForm(string url, int maxFrameRate = 30)
this.Renderer.Render += renderer_Render;

this.url = url;

Util.Hide(this);
}

public void Reload()
Expand Down
53 changes: 53 additions & 0 deletions OverlayPlugin/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace RainbowMage.OverlayPlugin
{
Expand Down Expand Up @@ -37,5 +39,56 @@ public static bool IsOnScreen(Form form)

return false;
}

[DllImport("user32.dll")]
public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)]
private static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

[DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)]
private static extern Int32 SetWindowLong(IntPtr hWnd, int nIndex, Int32 dwNewLong);

[DllImport("kernel32.dll", EntryPoint = "SetLastError")]
public static extern void SetLastError(int dwErrorCode);

private static int ptr32(IntPtr intPtr)
{
return unchecked((int)intPtr.ToInt64());
}

public static IntPtr SetWindowLongA(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
{
int error = 0;
IntPtr result = IntPtr.Zero;

SetLastError(0);

if (IntPtr.Size == 4)
{
Int32 result32 = SetWindowLong(hWnd, nIndex, ptr32(dwNewLong));
error = Marshal.GetLastWin32Error();
result = new IntPtr(result32);
}
else
{
result = SetWindowLongPtr(hWnd, nIndex, dwNewLong);
error = Marshal.GetLastWin32Error();
}

if ((result == IntPtr.Zero) && (error != 0))
{
throw new System.ComponentModel.Win32Exception(error);
}

return result;
}

public static void Hide(System.Windows.Forms.Form form)
{
int ex = (int)GetWindowLong(form.Handle, (int)(-20));
ex |= (int)(0x00000080);
SetWindowLongA(form.Handle, (int)(-20), (IntPtr)ex);
}
}
}

0 comments on commit 7909f30

Please sign in to comment.