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 = getWindowTit
mfc获取其它程序窗口句柄
最新推荐文章于 2022-04-30 14:45:05 发布
该博客介绍了如何在MFC中通过EnumWindows和EnumChildWindows函数获取其他程序的窗口句柄,并比较窗口标题,特别针对名为'waw.exe'的窗口进行了示例操作。主要函数包括获取窗口标题的getWindowTitle,比较两个字符串的equal,以及显示消息框的show。在OnBnClickedOk事件中调用了EnumWindows遍历顶层窗口,寻找特定标题的窗口。
摘要由CSDN通过智能技术生成