#include <windows.h>
#include <iostream>
#include <vector>
// 콜백 함수: 하위 윈도우 열거용
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) {
wchar_t class_name[256] = { 0 };
GetClassName(hwnd, class_name, sizeof(class_name));
// 클래스 이름이 "EVA_ChildWindow"인지 확인
if (wcscmp(class_name, L"EVA_ChildWindow") == 0) {
std::vector<HWND> *target_handles = reinterpret_cast<std::vector<HWND>*>(lParam);
target_handles->push_back(hwnd);
}
return TRUE; // 계속 열거
}
int main() {
// 1. 클래스 이름이 "EVA_Window_Dblclk"이고 캡션 이름이 "카카오톡"인 윈도우 핸들 찾기
HWND parent_handle = FindWindowEx(NULL, NULL, L"EVA_Window_Dblclk", L"카카오톡");
if (!parent_handle) {
std::cout << "No window found with class name 'EVA_Window_Dblclk' and caption '카카오톡'." << std::endl;
return 1;
}
// 2. 해당 부모 핸들 아래 클래스 이름이 "EVA_ChildWindow"인 모든 자식 핸들 찾기
std::vector<HWND> child_handles;
EnumChildWindows(parent_handle, EnumChildProc, reinterpret_cast<LPARAM>(&child_handles));
if (!child_handles.empty()) {
std::cout << "Parent Window Handle: " << parent_handle << std::endl;
for (HWND hwnd : child_handles) {
std::cout << "Child Window Handle: " << hwnd << std::endl;
}
}
else {
std::cout << "No child window found with class name 'EVA_ChildWindow'." << std::endl;
}
return 0;
}