c++ - 获取外部运行的可见窗口c++的句柄

标签 c++ windows external hwnd

问题是,我想获取所有可见窗口的句柄。到目前为止,我已经实现了获取包含子字符串的窗口的hwnd。这是我的代码。我提到的 block 在评论中,但我找不到任何方法来检查窗口的可见性。

提前致谢:)

#include <string.h>
#include <tchar.h>
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

vector<HWND> asd,myVector;
HWND temp;

BOOL CALLBACK addToVector(HWND hwnd, LPARAM windowName)
{
    myVector.push_back(hwnd);
    //to get desired windows filtering by window name as substring
    /*

    TCHAR windowTitle[512];
    if (GetWindowText(hwnd, windowTitle, 512))
    {   
        if (_tcsstr(windowTitle, LPCTSTR(windowName)) != NULL)
        {
            myVector.push_back(hwnd);
        }
    }
    */
    return true; 
}

int main() 
{
    char substring[] = "chrome";
    EnumWindows(addToVector, (LPARAM)substring);

    cout << myVector.size() << endl;

    getchar();

    return 0;
}

最佳答案

您可以通过调用 IsWindowVisible() 来确定窗口是否可见.

if(IsWindowVisible(hwnd))
{
    myVector.push_back(hwnd);
}

关于c++ - 获取外部运行的可见窗口c++的句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24396767/

相关文章:

c - HP Code Wars 检查数字算法错误

windows - 批处理文件功能执行时间过长

java - 将值传递给 Java 中的外部方法

python - 导入和定义在被调用脚本中的正确位置?

c++ - 为什么自动返回类型会改变重载分辨率?

c++ - 使用 C++ for Windows 加速套接字 WinHttp API 终止的方法

c - 在 Windows 上格式化文件

c++ - Qt 线程中未检测到信号和插槽

c++ - 为什么私有(private)继承不能解决静态函数的歧义? (在 MSVC 中测试)

android - 无法在我的设备 android 上写入 SD 卡