win32-EnumChildWindows use

#include <Windows.h>
#include <iostream>
#include <string>

static BOOL CALLBACK enumchildWindowCallback(HWND hWnd, LPARAM lparam) {
    int length = GetWindowTextLength(hWnd);
    char * buffer = new char[length + 1];
    GetWindowText(hWnd, buffer, length + 1);
    std::string windowTitle(buffer);

    std::cout << hWnd << ":  " << windowTitle << std::endl;

    return TRUE;
}

int main ()
{
    HWND the HWND = (the HWND) 0x000D0DEE ; // parent window handle 
    EnumChildWindows (hwnd, enumchildWindowCallback, NULL) ;

    std::cin.ignore();
    return 0;
}

Development: Use EnumWindows enumerate window handle (not including child windows)

#include <Windows.h>
#include <string>
#include <iostream>

static BOOL CALLBACK enumchildWindowCallback(HWND hWnd, LPARAM lparam) {
int length = GetWindowTextLength(hWnd);
char* buffer = new char[length + 1];
GetWindowText(hWnd, buffer, length + 1);
std::string windowTitle(buffer);

int n = (int)hWnd;
// Ignore windows if invisible or missing a title
//    if (IsWindowVisible(hWnd) && length != 0) {
std::cout << n << ": " << windowTitle << std::endl;
//    }
return TRUE;
}

static BOOL CALLBACK enumWindowCallback(HWND hWnd, LPARAM m) {
TCHAR _classbuf[255];
int length = GetWindowTextLength(hWnd);
char* buffer = new char[length + 1];
GetWindowText(hWnd, buffer, length + 1);
std::string windowTitle(buffer);
m = GetClassName(hWnd, _classbuf, 1024);
int n = (int)hWnd;
// Ignore windows if invisible or missing a title
//    if (IsWindowVisible(hWnd) && length != 0) {
std::cout << n << ": " << windowTitle << std::endl;
//    EnumChildWindows(hWnd, enumWindowCallback, m);
//    }
return TRUE;
}

int main ()
{
std::cout << "Enmumerating windows..." << std::endl;
EnumWindows (enumWindowCallback, NULL);

std::cin.ignore();
return 0;

}
If you remove EnumChildWindows (hWnd, enumWindowCallback, m) Notes, enumerate all windows

Guess you like

Origin www.cnblogs.com/strive-sun/p/12653803.html