【问题标题】:Getting handle of externally running visible windows c++获取外部运行的可见窗口 c++ 的句柄
【发布时间】:2014-06-24 21:38:10
【问题描述】:

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

提前致谢:)

#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;
}

【问题讨论】:

    标签: c++ windows external hwnd


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢你,我还添加了一个条件 if(IsWindowVisible(hwnd) && GetWindowText(hwnd, windowTitle, 512))。
    • 你也可以在里面添加比较if(visible &amp;&amp; getname &amp;&amp; comparename) { ... }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 2010-12-05
    相关资源
    最近更新 更多