获取有关所有正在运行的应用程序C ++

时间:2015-10-03 16:44:20

标签: c++ windows visual-studio-2013 process

我需要使用C ++获取所有正在运行的应用程序打开或最小化的详细信息以及它们的窗口宽度,高度和坐标。

这是我目前正在使用的代码

#include <iostream>
#include <windows.h>
using namespace std;

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);

int main()
{
    EnumWindows(EnumWindowsProc, NULL);
    int d;
    cin >> d;

    return 0;
}

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    RECT windrect;
    char class_name[80];
    char title[80];
    GetClassNameA(hwnd, class_name, sizeof(class_name));
    GetWindowTextA(hwnd, title, sizeof(title));
    GetWindowRect(hwnd, &windrect);
    LONG width = windrect.right - windrect.left;
    LONG height = windrect.bottom - windrect.top;
    if (width > 0 && height > 0 && &title[0]!=" "){
        cout << "width: " << width;
        cout << "height: " << height;
        cout << "Window title: " << title << endl;
        cout << "Class name: " << class_name << endl << endl;
    }
    return TRUE;
}

使用EnumWindowsProc但是它列出了所有不显示窗口的正在运行的进程。

这是我得到的输出:

output output2 output3

所以基本上它列举了很多进程,而我需要的只是有关打开窗口运行的应用程序的详细信息。它的高度,宽度和坐标。

我应该使用什么函数代替EnumWindowsProc,以便只获取窗口进程的详细信息。

0 个答案:

没有答案