C++ 批量获取系统运行窗口得标题

180it 2021-09-14 PM 1544℃ 0条
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>

void EnumetareWindows(HWND hWndParent)
{
    char szBuff[512];
    GetWindowTextA(hWndParent, szBuff, _countof(szBuff));
    printf("%s\n", szBuff);

    HWND hWndChild = FindWindowEx(hWndParent, NULL, NULL, NULL);
    if (hWndChild == NULL) {
        return;
    }

    do {
        EnumetareWindows(hWndChild);
    } while ( (hWndChild = FindWindowEx(hWndParent, hWndChild, NULL, NULL)) != NULL );
}

int main()
{
    HWND hWndParent = GetDesktopWindow();
    EnumetareWindows(hWndParent);
    return 0;
}

方法2:

#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>

typedef BOOL (*LPFNENUMERATEWINDOWCALLBACK)(HWND hWnd);

void EnumetareWindows(HWND hWndParent, LPFNENUMERATEWINDOWCALLBACK lpfnCallback)
{
    if (lpfnCallback(hWndParent) == FALSE) {
        return;
    }

    HWND hWndChild = FindWindowEx(hWndParent, NULL, NULL, NULL);
    if (hWndChild == NULL) {
        return;
    }

    do {
        EnumetareWindows(hWndChild, lpfnCallback);
    } while ( (hWndChild = FindWindowEx(hWndParent, hWndChild, NULL, NULL)) != NULL );
}

BOOL SetWindowTextCallback(HWND hWnd)
{
    char szBuff[512];
    GetWindowTextA(hWnd, szBuff, _countof(szBuff));
    printf("%s\n", szBuff);
    return TRUE;
}

int main()
{
    HWND hWndParent = GetDesktopWindow();
    EnumetareWindows(hWndParent, SetWindowTextCallback);
    return 0;
}
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

C++ 批量获取系统运行窗口得标题