我已经使用 WPF(C# 和 XAML)创建了一个记分板应用程序,当我通过复选框启用对它的锁定时,我需要使一个窗口完全无响应。这意味着您无法单击它,光标不会改变,尤其是当您单击它时不会出现 Windows 任务栏。此记分牌位于游戏顶部,记分牌是最顶部的窗口,但由于某种原因,我无法使其完全无法点击。
我已经尝试过 IsHitTestVisible、Focusable、IsManipulationEnabled、ResizeMode、WindowStyle 并将它们都设置为 false 没有任何效果。我仍然可以单击窗口,它会调出 Window 的任务栏,当您有一个应该全屏窗口的游戏时,它会变得很烦人。
我能做些什么呢?
更新:
通过更改一些谷歌搜索词找到了答案。
Win32 类
//Rest of this code in located in the class itself
public const int WS_EX_TRANSPARENT = 0x00000020;
public const int GWL_EXSTYLE = (-20);
[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr hwnd,
int index);
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hwnd,
int index, int newStyle);
public static void makeTransparent(IntPtr hwnd)
{
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
Win32.SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
public static void makeNotTransparent(IntPtr hwnd)
{
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
Win32.SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle ^ WS_EX_TRANSPARENT);
}
事件
base.OnSourceInitialized(e);
IntPtr hwnd = new WindowInteropHelper(yourWindow).Handle;
Win32.makeTransparent(hwnd);