55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using System;
|
|
using System.Windows;
|
|
using System.Windows.Interop;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Conjure.Arcade.Overlay
|
|
{
|
|
public class OverlayWindow : Window
|
|
{
|
|
[DllImport("user32.dll")]
|
|
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
|
|
|
[DllImport("user32.dll")]
|
|
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
|
|
|
private const int GWL_EXSTYLE = -20;
|
|
private const int WS_EX_TRANSPARENT = 0x20;
|
|
private const int WS_EX_LAYERED = 0x80000;
|
|
private bool _isClickThrough = true;
|
|
|
|
public OverlayWindow()
|
|
{
|
|
// Make window transparent and click-through
|
|
WindowStyle = WindowStyle.None;
|
|
AllowsTransparency = true;
|
|
Background = null;
|
|
Topmost = true;
|
|
ShowInTaskbar = false;
|
|
|
|
// Handle window creation
|
|
SourceInitialized += OnSourceInitialized;
|
|
}
|
|
|
|
private void OnSourceInitialized(object? sender, EventArgs e)
|
|
{
|
|
var hwnd = new WindowInteropHelper(this).Handle;
|
|
var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
|
|
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT | WS_EX_LAYERED);
|
|
}
|
|
|
|
public void SetClickThrough(bool enabled)
|
|
{
|
|
var hwnd = new WindowInteropHelper(this).Handle;
|
|
var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
|
|
|
|
if (enabled)
|
|
extendedStyle |= WS_EX_TRANSPARENT;
|
|
else
|
|
extendedStyle &= ~WS_EX_TRANSPARENT;
|
|
|
|
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle);
|
|
_isClickThrough = enabled;
|
|
}
|
|
}
|
|
} |