您的位置:首页 > 其它

mfc获取其它程序窗口句柄

2016-05-30 17:18 274 查看
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 );  

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐