mfc获取其它程序窗口句柄

该博客介绍了如何在MFC中通过EnumWindows和EnumChildWindows函数获取其他程序的窗口句柄,并比较窗口标题,特别针对名为'waw.exe'的窗口进行了示例操作。主要函数包括获取窗口标题的getWindowTitle,比较两个字符串的equal,以及显示消息框的show。在OnBnClickedOk事件中调用了EnumWindows遍历顶层窗口,寻找特定标题的窗口。
摘要由CSDN通过智能技术生成
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值