Win32API的EnumWindows()
可以枚举桌面所有窗口,且枚举顺序是从顶层窗口到底层窗口,回调函数EnumWindowsProc()
返回0可提前结束枚举过程,测试代码如下:
#include <windows.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#pragma comment(lib, "User32.lib")
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam){
if(IsWindowVisible(hwnd)){
char buffer[256];
int len = GetWindowTextA(hwnd, buffer, 256);
buffer[len] = 0;
WINDOWINFO winInfo = {0};
winInfo.cbSize = sizeof(WINDOWINFO);
GetWindowInfo(hwnd, &winInfo);
printf("%016llx %10llu: %08X %08X %u [%6d %6d %6d %6d] [%6d %6d %6d %6d] %s\n",
(uint64_t)hwnd,
(uint64_t)hwnd,
winInfo.dwStyle,
winInfo.dwExStyle,
winInfo.dwWindowStatus,
winInfo.rcWindow.left, winInfo.rcWindow.top, winInfo.rcWindow.right, winInfo.rcWindow.bottom,
winInfo.rcClient.left, winInfo.rcClient.top, winInfo.rcClient.right, winInfo.rcClient.bottom,
buffer
);
}
return 1;
}
int main(int argc, char* argv[]){
EnumWindows(EnumWindowsProc, 0);
return 0;
}
运行效果如图:
网友评论