gpt4 book ai didi

c++ - SetWindowDisplayAffinity 在 MFC 窗口中不起作用

转载 作者:行者123 更新时间:2023-12-03 07:21:04 33 4
gpt4 key购买 nike

我有 1 优化校准并想做不能录屏 .
在.Net中,我一直在使用 SetWindowDisplayAffinity :

WDA_MONTOR = 1;
SetWindowDisplayAffinity(this.Handle, WDA_MONTOR);
现在我搬到了 MFC 为本地性能。
我正在使用以下代码,它不会阻止 截图 :
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说“参数不正确”。

最佳答案

根据 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). Use the top-level window.


这意味着我必须使用 表格 处理而不是 图片框 处理。
所以改变
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);
原因: 表格 窗口是 家长 顶级 window 。

关于c++ - SetWindowDisplayAffinity 在 MFC 窗口中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65091056/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com