如何撤消 SetWindowDisplayAffinity 方法?

问题描述 投票:0回答:1

我有一个阻止屏幕捕获的 C# 应用程序,但我想禁用“黑屏”。

这是我的代码:

[DllImport("user32.dll")]
public static extern uint SetWindowDisplayAffinity(IntPtr hWnd, uint dwAffinity);

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    SetWindowDisplayAffinity(this.Handle, WDA_MONITOR);
}

我可以通过什么方式禁用它?

c# .net winforms user32
1个回答
4
投票

使用 SetWindowDisplayAffinity,要从捕获中排除窗口,请传递

WDA_EXCLUDEFROMCAPTURE
WDA_MONITOR
作为参数,要撤消(包含在捕获中),请传递
WDA_NONE
:

[DllImport("user32.dll")]
static extern uint SetWindowDisplayAffinity(IntPtr hWnd, uint dwAffinity);
const uint WDA_NONE = 0x00000000;
const uint WDA_MONITOR = 0x00000001;
const uint WDA_EXCLUDEFROMCAPTURE = 0x00000011;

private void includeButton_Click(object sender, EventArgs e)
{
    SetWindowDisplayAffinity(this.Handle, WDA_NONE);
}

private void excludeButton_Click(object sender, EventArgs e)
{
    SetWindowDisplayAffinity(this.Handle, WDA_MONITOR);
}

以下屏幕截图显示该窗口包含在捕获中:

以下屏幕截图显示该窗口被排除在捕获之外:

© www.soinside.com 2019 - 2024. All rights reserved.