【发布时间】:2013-06-30 22:09:42
【问题描述】:
我已经使用 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);
【问题讨论】:
-
我不知道单独记分板的想法。为什么不像大多数游戏那样创建一个被绘制到游戏窗口的图像呢?还是我错过了什么?
-
我也有同样的问题。我想当用户右键单击不可点击的窗口时,它后面的窗口(或桌面)对这个事件做出反应。如果我们使用 Linux 或 Mac-OS 等其他平台,该怎么办?
-
@ChiefTwoPencils 他们可能无法控制原始游戏。