SetWindowDisplayAffinity 在 MFC 中不起作用 windows
SetWindowDisplayAffinity not works in MFC windows
我有 1 个图片控制,想把它不能录屏。
在 .Net 中,我一直在使用 SetWindowDisplayAffinity
:
WDA_MONTOR = 1;
SetWindowDisplayAffinity(this.Handle, WDA_MONTOR);
现在我已经转移到 MFC 以获得原生性能。
我正在使用以下代码,它不会阻止 screenshots:
HWND Handle = this->GetDlgItem(IDC_SCREEN)->m_hWnd;
SetWindowDisplayAffinity(Handle, WDA_MONITOR);
完整示例:
if(SetWindowDisplayAffinity(hWnd, WDA_MONITOR)==false)
{
wchar_t buf[256];
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf, (sizeof(buf) / sizeof(wchar_t)), NULL);
AfxMessageBox(buf);
}
GetLastError
说“参数不正确”。
根据 :
The .NET version was passing the form's window handle (a top-level window), but your MFC version is passing a control's window handle (a child window). Use the top-level window.
这意味着我必须使用 Form 句柄而不是 PictureBox 句柄。
所以改变
HWND Handle = this->GetDlgItem(IDC_SCREEN)->m_hWnd; //PictureBox handle
SetWindowDisplayAffinity(Handle, WDA_MONITOR);
到
HWND Handle = this->m_hWnd; //form handle
SetWindowDisplayAffinity(Handle, WDA_MONITOR);
原因:Form window 是 parent and top-level window.
我有 1 个图片控制,想把它不能录屏。
在 .Net 中,我一直在使用 SetWindowDisplayAffinity
:
WDA_MONTOR = 1;
SetWindowDisplayAffinity(this.Handle, WDA_MONTOR);
现在我已经转移到 MFC 以获得原生性能。
我正在使用以下代码,它不会阻止 screenshots:
HWND Handle = this->GetDlgItem(IDC_SCREEN)->m_hWnd;
SetWindowDisplayAffinity(Handle, WDA_MONITOR);
完整示例:
if(SetWindowDisplayAffinity(hWnd, WDA_MONITOR)==false)
{
wchar_t buf[256];
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf, (sizeof(buf) / sizeof(wchar_t)), NULL);
AfxMessageBox(buf);
}
GetLastError
说“参数不正确”。
根据
The .NET version was passing the form's window handle (a top-level window), but your MFC version is passing a control's window handle (a child window). Use the top-level window.
这意味着我必须使用 Form 句柄而不是 PictureBox 句柄。 所以改变
HWND Handle = this->GetDlgItem(IDC_SCREEN)->m_hWnd; //PictureBox handle
SetWindowDisplayAffinity(Handle, WDA_MONITOR);
到
HWND Handle = this->m_hWnd; //form handle
SetWindowDisplayAffinity(Handle, WDA_MONITOR);
原因:Form window 是 parent and top-level window.