Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SetWindowLong启用/禁用点击表单_C#_.net - Fatal编程技术网

C# SetWindowLong启用/禁用点击表单

C# SetWindowLong启用/禁用点击表单,c#,.net,C#,.net,因此,这成功地使我的应用程序“点击通过”,所以它可以保持最顶端,但我仍然可以点击它后面的应用程序。 它使用了一段流行的代码,但我的问题是,如何禁用它 如何将其还原,以便在不重新启动应用程序的情况下再次单击应用程序 public enum GWL { ExStyle = -20 } public enum WS_EX { Transparent = 0x20, Layered = 0x80000 }

因此,这成功地使我的应用程序“点击通过”,所以它可以保持最顶端,但我仍然可以点击它后面的应用程序。 它使用了一段流行的代码,但我的问题是,如何禁用它

如何将其还原,以便在不重新启动应用程序的情况下再次单击应用程序

public enum GWL
    {
        ExStyle = -20
    }

    public enum WS_EX
    {
        Transparent = 0x20,
        Layered = 0x80000
    }

    public enum LWA
    {
        ColorKey = 0x1,
        Alpha = 0x2
    }

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

    [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
    public static extern int SetWindowLong(IntPtr hWnd, GWL nIndex, int dwNewLong);

    [DllImport("user32.dll", EntryPoint = "SetLayeredWindowAttributes")]
    public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, int crKey, byte alpha, LWA dwFlags);

void ClickThrough()
{
int wl = GetWindowLong(this.Handle, GWL.ExStyle);
                wl = wl | 0x80000 | 0x20;
                SetWindowLong(this.Handle, GWL.ExStyle, wl);
}
在这里,您使用按位或添加标志
WS_EX_LAYERED
WS_EX_TRANSPARENT
。不管它值多少钱,像这样使用魔法常数是很糟糕的。使用适当的名称声明常量:

wl = wl | 0x80000 | 0x20;
为了方便起见,可以在
GetWindowLong
SetWindowLong
中使用
uint

public const uint WS_EX_LAYERED = 0x00080000;
public const uint WS_EX_TRANSPARENT = 0x00000020;
然后按如下方式设置扩展样式:

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

[DllImport("user32.dll")]
public static extern uint SetWindowLong(IntPtr hWnd, GWL nIndex, uint dwNewLong);
按如下方式反转此更改:

uint ex_style = GetWindowLong(this.Handle, GWL.ExStyle);
SetWindowLong(this.Handle, GWL.ExStyle, ex_style | WS_EX_LAYERED | WS_EX_TRANSPARENT);

您可以对样式使用枚举,但这对我来说似乎有点不合适,因为值与按位操作相结合。因此我更喜欢使用
uint

Oo,非常感谢!反应很好。我会向上投票,但没有足够的代表。接受我想象中的向上投票。
!WS_EX_分层
:操作员'!'无法应用于“uint”类型的操作数
uint ex_style = GetWindowLong(this.Handle, GWL.ExStyle);
SetWindowLong(this.Handle, GWL.ExStyle, ex_style & !WS_EX_LAYERED & !WS_EX_TRANSPARENT);