#include <Windows.h>
#include <stdio.h>
#include <iostream>
static const int s_max = 1024;
BOOL CALLBACK EnumWindowsProc(HWND, LPARAM);
BOOL CALLBACK EnumChildWindowsProc(HWND, LPARAM);
int main()
{
EnumWindows(EnumWindowsProc, NULL);
system("pause");
return 0;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lparam)
{
if (hwnd) {
char text[s_max] = { 0 };
GetWindowText(hwnd, text, s_max);
if (strlen(text) > 0) {
if (strcmp(text, "abc.txt - 记事本") == 0) {
EnumChildWindows(hwnd, EnumChildWindowsProc, NULL);
}
}
return TRUE;
}
return FALSE;
}
BOOL CALLBACK EnumChildWindowsProc(HWND hwnd, LPARAM)
{
if (hwnd) {
char text[s_max] = { 0 };
GetWindowText(hwnd, text, s_max);
std::cout << "child:" << text << std::endl;
return TRUE;
}
return FALSE;
}
枚举句柄
最新推荐文章于 2024-04-03 00:44:01 发布