上代码:
代码语言:javascript复制#include <QDebug>
#include <windows.h>
#pragma comment(lib,"user32.lib")
/* 回调函数,用于捕获进程 */
BOOL MyEnumProc(HWND hwnd, LPARAM param)
{
LPWSTR lpString = (LPWSTR)malloc(sizeof(WCHAR) * MAX_PATH);
if (IsWindow(hwnd) &&
IsWindowEnabled(hwnd) &&
IsWindowVisible(hwnd))
{
if (GetWindowTextW(hwnd, lpString, MAX_PATH) > 0) {
qDebug() << QString::fromStdWString(lpString); // 打印出有标题的窗口
}
}
free(lpString);
return TRUE;
}
int main(int argc, char *argv[])
{
/* 枚举窗口的所有进程 */
EnumWindows(MyEnumProc, 0);
return 0;
}