#include <Windows.h>
#include <Dwmapi.h>
#include <iostream>
#pragma comment(lib, "dwmapi.lib")
int main(int argc, char* argv[])
{
//获取桌面句柄
auto hwnd = GetDesktopWindow();
//获取桌面子窗口句柄
hwnd = GetWindow(hwnd, GW_CHILD);
auto counter = 0;
while (hwnd != NULL)
{
RECT rect;
//获取窗口大小
DwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &rect, sizeof(RECT));
//获取窗口名
char name[255];
GetWindowText(hwnd, name, 255);
if (!std::string(name).empty())
{
std::cout << "#" << counter++ << " " << name
<< ": (" << rect.left << ", " << rect.top << ") - "
<< rect.right - rect.left << " x " << rect.bottom - rect.top << std::endl;
}
hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);
}
return 0;
}