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 );
}
相关文章推荐
- HDU 5378 (概率dp)
- zookeeper概要整理
- Android平台Native开发与JNI机制详解
- 【C++】认识模版函数
- 【C++】模版实现双向链表的各种操作(如:逆置、去重Unique、分类(冒泡)、合并)
- 【C++】容器适配器实现栈Stack的各种功能(入栈、出栈、判空、大小、访问所有元素等)
- 【C++】容器适配器实现队列Queue的各种功能(入队、出队、判空、大小、访问所有元素等)
- 论IT就业发展趋势
- 【C++】类型萃取技术实现静态顺序表
- 【C++】智能指针的作用,模拟实现auto_ptr,scoped_ptr,shared_ptr,scoped_array,shared_array
- 【C语言】求斐波那契(Fibonacci)数列通项(递归法、非递归法)
- 【数据结构】使用栈Stack解决迷宫问题
- 【数据结构】(面试题)使用两个栈实现一个队列(详细介绍)
- 【数据结构】对称矩阵及对称矩阵的压缩存储
- 【数据结构】稀疏结构及稀疏矩阵的压缩存储,矩阵的(快速)转置
- 【数据结构】广义表的默认成员函数、深度、大小、打印
- 【C语言】str类与men库函数的实现(如:strcpy,strcmp,strstr,strcat,memmove,memcpy)
- 【数据结构】二叉树的实现(如:默认成员函数、(叶子)节点数、深度、四种遍历)
- 【数据结构】二叉树(前、中、后)序遍历的递归与非递归算法
- 【数据结构】堆的实现(包括:默认成员函数,插元素push,删元素pop,访问根节点top,判空,大小)