C++ 具有enumwindows接口和进程的程序列表

C++ 具有enumwindows接口和进程的程序列表,c++,interface,window,C++,Interface,Window,我需要找到所有打开的带有图形界面的窗口和它们的流程,但我真的不知道如何去做。我已经编写了一些代码,但我刚刚成功地找到了打开的窗口: HWND hwnd = GetForegroundWindow(); // get handle of currently active window GetWindowText(hwnd, wnd_title, sizeof(wnd_title)); cout << "Window with focus: " << wnd_title &l

我需要找到所有打开的带有图形界面的窗口和它们的流程,但我真的不知道如何去做。我已经编写了一些代码,但我刚刚成功地找到了打开的窗口:

HWND hwnd = GetForegroundWindow(); // get handle of currently active window
GetWindowText(hwnd, wnd_title, sizeof(wnd_title));
cout << "Window with focus: " << wnd_title << endl << endl;

EnumWindows(EnumWindowsProc, 0); 
HWND-HWND=getForeGroundIndow();//获取当前活动窗口的句柄
GetWindowText(hwnd、wnd_标题、sizeof(wnd_标题));

cout我建议您不要检查
IsWindowVisible
,因为

如果指定的窗口、其父窗口、其父窗口的父窗口等具有WS\u VISIBLE样式,则返回值为非零。否则,返回值为零。
由于返回值指定窗口是否具有“WS_VISIBLE样式”,因此即使窗口被其他窗口完全遮挡,返回值也可能为非零

在枚举窗口时,您可以使用它来检索与特定
HWND
相关的进程id

例如:

BOOL回调EnumWindowsProc(HWND-HWND,LPARAM-LPARAM)
{
字符类_名称[80];
字符标题[80];
DWORD dwProcessId;
GetClassName(hwnd,class_name,sizeof(class_name));
GetWindowText(hwnd,title,sizeof(title));
//基于hwnd获取进程id
GetWindowThreadProcessId(hwnd和dwProcessId);

std::cout,是否可以找到每个窗口都对应的应用程序?@ica是的,这应该完全满足您的需要,但我不确定它是否会显示重复的进程ID,因为一个进程可以有多个窗口。因为我还需要找到与打开的应用程序关联的图标,我不知道是否可以从win中找到它dows@ica获取图标相当容易,您只需调用
GetClassLong(hwnd,GCL_HICON);
该函数返回句柄…我需要将图标发送到客户端…是否可以使用句柄?
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    char class_name[80];
    char title[80];

    if (IsWindowVisible(hwnd)) {
        GetClassName(hwnd, class_name, sizeof(class_name));
        GetWindowText(hwnd, title, sizeof(title));
        cout << "Window title: " << title << endl;
        cout << "Class name: " << class_name << endl << endl;
    }   
    return TRUE;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    char class_name[80];
    char title[80];
    DWORD dwProcessId;
    GetClassName(hwnd,class_name, sizeof(class_name));
    GetWindowText(hwnd,title,sizeof(title));

    // get process id based on hwnd
    GetWindowThreadProcessId(hwnd, &dwProcessId);

    std::cout << "Window title: "<< title << std::endl;
    std::cout << "Class name: "<< class_name << std::endl
    // display process id based on hwnd
    std::cout << "Process Id: " << dwProcessId  << std::endl;

    return TRUE;
}