const char *getWindowTitle(HWND hWnd){
char WindowTitle[1000]={0};
::GetWindowText(hWnd,WindowTitle,1000);
std::string *title = new std::string(WindowTitle);
return (*title).c_str();
}
bool equal(const char *a, const char *b){
return strcmp(a, b) == 0;
}
void show(const char *message){
AfxMessageBox(message);
}
//EnumChildWindows回调函数,hwnd为指定的父窗口
BOOL CALLBACK EnumChildWindowsProc(HWND hWnd,LPARAM lParam)
{
char WindowTitle[1000]={0};
::GetWindowText(hWnd,WindowTitle,1000);
printf("%s\n",WindowTitle);
if(equal( getWindowTitle(GetParent(hWnd)), getWindowTitle(hWnd))){
//show(WindowTitle);
}
return true;
}
//EnumWindows回调函数,hwnd为发现的顶层窗口
BOOL CALLBACK EnumWindowsProc(HWND hWnd,LPARAM lParam)
{
if (GetParent(hWnd)==NULL && IsWindowVisible(hWnd) ) //判断是否顶层窗口并且可见
{
const char *WindowTitle = getWindowTitle (hWnd);
EnumChildWindows(hWnd,EnumChildWindowsProc,NULL); //获取父窗口的所有子窗口
if(equal(WindowTitle, "waw.exe")){
show(WindowTitle);
return false;
}
}
return true;
}
void CwawWithLogDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
// CDialogEx::OnOK();
EnumWindows(EnumWindowsProc ,NULL );
}