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:
Window expluded from capture:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…