[英]SetWindowDisplayAffinity not works in MFC windows
I have 1 Picture Control and want to make it not screen record-able .我有 1 个优化校准并想让它不能录制屏幕。
In.Net, I have been using SetWindowDisplayAffinity
:在.Net 中,我一直在使用SetWindowDisplayAffinity
:
WDA_MONTOR = 1;
SetWindowDisplayAffinity(this.Handle, WDA_MONTOR);
Now I have moved to MFC for native performance.现在我已经转移到MFC以获得本机性能。
I am using this following code which don't prevent screenshots :我正在使用以下不会阻止屏幕截图的代码:
HWND Handle = this->GetDlgItem(IDC_SCREEN)->m_hWnd;
SetWindowDisplayAffinity(Handle, WDA_MONITOR);
Complete example:完整示例:
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
says "parameter is incorrect". GetLastError
说“参数不正确”。
According to Raymond chen :据雷蒙德陈说:
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). .NET 版本正在传递窗体的 window 句柄(顶级窗口),但您的 MFC 版本正在传递控件的 window 句柄(子窗口)。 Use the top-level window.使用顶级 window。
That's mean I would have to use Form handle instead of PictureBox handle.这意味着我将不得不使用Form句柄而不是PictureBox句柄。 So change所以改变
HWND Handle = this->GetDlgItem(IDC_SCREEN)->m_hWnd; //PictureBox handle
SetWindowDisplayAffinity(Handle, WDA_MONITOR);
to到
HWND Handle = this->m_hWnd; //form handle
SetWindowDisplayAffinity(Handle, WDA_MONITOR);
Reason: Form window is parent and top-level window.原因:表格window 是父表格和顶级表格 window。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.