这里写自定义目录标题
#include <Windows.h>
#include
#include
// 存储控件信息的结构
struct ControlInfo {
HWND hwnd;
std::wstring className;
std::wstring title;
int id;
};
// 回调函数,用于 enumerate 子窗口
BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam) {
std::vector* pControls = reinterpret_cast<std::vector*>(lParam);
// 获取控件的类名
wchar_t className[256];
GetClassName(hwndChild, className, sizeof(className) / sizeof(wchar_t));
// 获取控件的标题
wchar_t title[256];
GetWindowText(hwndChild, title, sizeof(title) / sizeof(wchar_t));
// 获取控件的ID
int id = GetDlgCtrlID(hwndChild);
// 将控件信息添加到列表
pControls->push_back({ hwndChild, className, title, id });
return TRUE; // 继续枚举
}
void EnumAllChildWindows(HWND hwndParent) {
std::vector controls;
// 枚举父窗口的所有子窗口
EnumChildWindows(hwndParent, EnumChildProc, reinterpret_cast<LPARAM>(&controls));
// 打印控件信息
std::wcout << L"找到以下控件:" << std::endl;
for (const auto& control : controls) {
std::wcout << L"句柄: " << control.hwnd << L", 类名: " << control.className
<< L", 标题: " << control.title << L", ID: " << control.id << std::endl;
}
}
int main() {
// 替换为您要枚举的父窗口标题
HWND hwndParent = FindWindow(NULL, L"子窗口标题"); // 获取指定窗口的句柄
if (hwndParent == NULL) {
std::cout << “未找到指定的窗口!” << std::endl;
return 1;
}
// 枚举并打印子窗口信息
EnumAllChildWindows(hwndParent);
return 0;
}