SetWindowDisplayAffinity 不适用于控制台应用程序

SetWindowDisplayAffinity does not work for console app

我收到 accessdenied(5) 错误,是否有保护控制台 window 不被截图的方法?

int wmain(void)
{
    HWND hWnd = GetConsoleWindow();
    BOOL b = SetWindowDisplayAffinity(hWnd, WDA_MONITOR);
    DWORD e = GetLastError();
    return 0;
}

根据 documentation:

Parameters

hWnd

Type: HWND

A handle to the top-level window. The window must belong to the current process.

控制台不属于当前进程,无法设置HWND