winforms 如何撤消SetWindowDisplayAffinity方法?

r7s23pms  于 8个月前  发布在  其他
关注(0)|答案(1)|浏览(119)

我有一个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);
}

怎样才能使它失效?

zvokhttg

zvokhttg1#

使用SetWindowDisplayAffinity,要从捕获中排除窗口,传递WDA_EXCLUDEFROMCAPTUREWDA_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);
}

下面的屏幕截图显示了窗口包含在捕获中:

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

相关问题