Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
887 views
in Technique[技术] by (71.8m points)

c# - How can I undo SetWindowDisplayAffinity method?

I have a C# application that prevents screen capturing, but I want to disable "black screen".

Here is my code:

[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);
}

In which way I can disable it?

question from:https://stackoverflow.com/questions/65899149/how-can-i-undo-setwindowdisplayaffinity-method

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Using SetWindowDisplayAffinity, to exclude a window from capture, pass WDA_EXCLUDEFROMCAPTURE or WDA_MONITOR as parameter and to undo (include in capture), pass 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);
}

Window included in capture:

included

Window expluded from capture:

excluded


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...