【问题标题】:How can I undo SetWindowDisplayAffinity method?如何撤消 SetWindowDisplayAffinity 方法?
【发布时间】:2021-04-30 02:34:28
【问题描述】:

我有一个阻止屏幕捕获的 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】:

    使用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);
    }
    

    捕获中包含的窗口:

    从捕获中排除的窗口:

    【讨论】:

      猜你喜欢
      • 2021-06-01
      • 2014-04-12
      • 2018-06-15
      • 1970-01-01
      • 2019-12-11
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      相关资源
      最近更新 更多