dwm - DwmGetWindowAttribute 对子窗口不起作用,是真的吗?
问题描述
我正在尝试DwmGetWindowAttribute
在屏幕上获取窗口的真实、物理、像素位置。它适用于顶级窗口。但我发现它不适用于子窗口,在这种情况下它只返回E_HANDLE
(0x80070006)。
但是,MSDN没有说明这种子窗口限制。所以我很困惑。
任何人都可以确认这种行为吗?谢谢你。
这是我的 C++ 测试代码(DwmBounds.cpp):
#include <stdio.h>
#include <windows.h>
#include <dwmapi.h>
int main()
{
DWORD winerr = 0;
HWND hwndTop = FindWindow(L"Notepad", NULL);
if(!hwndTop)
{
wprintf(L"Cannot find a Notepad window.\n");
return 4;
}
RECT rc = {};
HRESULT hr = DwmGetWindowAttribute(hwndTop, DWMWA_EXTENDED_FRAME_BOUNDS, &rc, sizeof(rc));
if (hr != S_OK)
{
wprintf(L"Fail to call DwmGetWindowAttribute() on Notepad window. HRESULT=0x%08X\r\n",
(DWORD)hr);
return 4;
}
wprintf(L"Notepad DWMWA_EXTENDED_FRAME_BOUNDS: LT(%d, %d) RB(%d, %d)\r\n",
rc.left, rc.top, rc.right, rc.bottom);
HWND hwndEdit = FindWindowEx(hwndTop, nullptr, L"Edit", nullptr);
if (!hwndEdit)
return 4;
hr = DwmGetWindowAttribute(hwndEdit, DWMWA_EXTENDED_FRAME_BOUNDS, &rc, sizeof(rc));
if(hr != S_OK)
{
// Always get HRESULT=0x80070006 (E_HANDLE), why?
wprintf(L"Get DWMWA_EXTENDED_FRAME_BOUNDS fails on child window(0x%08X), HRESULT=0x%08X\n",
(DWORD)hwndEdit, (DWORD)hr);
return 4;
}
wprintf(L"Editbox DWMWA_EXTENDED_FRAME_BOUNDS: LT(%d, %d) RB(%d, %d)\r\n",
rc.left, rc.top, rc.right, rc.bottom);
return 0;
}
这是它的输出:
这样做的好处DwmGetWindowAttribute
是:无论DPI_AWARENESS_CONTEXT
调用线程上的设置如何,DwmGetWindowAttribute
总是报告物理屏幕坐标。另一方面,GetWindowRect
只报告与调用线程的 DPI-awareness-context 相关的“虚拟”坐标。所以,我想知道我是否可以DwmGetWindowAttribute
用来获取每个顶级窗口和子窗口的物理坐标。
解决方案
推荐阅读
- php - Laravel 自定义 Artisan 命令在完成 50% 时停止
- python - Python 在“if”中识别 9 大于 27
从字面上看,我已经进入学习之旅两天了,所以放轻松!我正在尝试组合一个基本的温度应用程序,除了输入个位数外,一切运行良好且没有错误。如果我输入两位数,它会正确记录正确的响应,例如:“是的,太热了”或“是的,太冷了”,但它似乎将任何低于 10 的值识别为大于 32 且不低于 27从而给出“太热情”的回应。
temper
- php - 币安 PHP API
- python - 使用虚拟环境时如何在 Windows cmd 中并行化 python 进程
- php - php & 似乎和 mysql & 不一样
- python - 如何访问python中字符串指定的变量?
- c++ - Boost::multi_index_container 具有不同的键和元素类型
- css - 如何使一个区域线显示在同一图表上的另一个区域之上?
- oracle-sqldeveloper - LISTAGG 函数:“字符串连接的结果太长”
- python - 如何在 azure 上安装 python bezier