Windows获取窗口列表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ice__snow/article/details/79980561

ENV

  • Windows 10
  • Visual Studio 2017

Source

#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;
        // https://stackoverflow.com/questions/34583160/winapi-createwindow-function-creates-smaller-windows-than-set
        // GetWindowRect(hwnd, &rect);
        DwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &rect, sizeof(RECT));

        char name[255];
        GetWindowText(hwnd, name, 255);

        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;
}
阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页