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 );
}