通过EnumWindows枚举顶层窗口,并显示窗口信息

The EnumWindows function enumerates all top-level windows on the screen by passing the handle to each window, in turn, to an application-defined callback function. EnumWindows continues until the last top-level window is enumerated or the callback function returns FALSE.
这是MSDN上关于EnumWindows函数的解释,意思是枚举所有处于顶层的窗口,但是什么是顶层窗口我并不是十分了解,因为从程序运行的结果我看不出所谓顶层窗口有什么共性,需要再研究研究,程序代码如下:

ContractedBlock.gif ExpandedBlockStart.gif Code
#include <windows.h>
char om[262144];
BOOL CALLBACK EnumWindowProc(HWND hWnd,LPARAM lParam);
BOOL CALLBACK EnumChildWindowProc(HWND hWnd,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
    HWND nphWnd
=::FindWindow("notepad",NULL);
    
if(nphWnd)
    {
        ::EnumWindows(EnumWindowProc,
0);//枚举窗口
        ::EnumChildWindows(nphWnd,EnumChildWindowProc,0);
    }
    
return 0;
}
BOOL CALLBACK EnumWindowProc(HWND hWnd,LPARAM lParam)
//枚举窗口的回调函数
{
    
char temp1[256];
    
char WinClassName[256];
    ::GetClassName(hWnd,WinClassName,
255);//获得类名
    DWORD pID=0;
    ::GetWindowThreadProcessId(hWnd,(LPDWORD)
&pID);//获得进程ID
    ::GetWindowText(hWnd,temp1,255);//获得窗口标题
    ::wsprintf(om,"%s%s%s%s%s%s%d",om,"\r\nclassname: ",WinClassName,",wintext: ",temp1,",ID:",pID);
    
return true;
}
BOOL CALLBACK EnumChildWindowProc(HWND hWnd,LPARAM lParam)
{
    
char temp1[256];
    
if(hWnd)
    {
        ::GetClassName(hWnd,temp1,
255);
        
if(!::strcmp(temp1,"Edit"))
        {
            ::SendMessage(hWnd,WM_SETTEXT,
0,(LPARAM)om);
            
return 0;
        }
    }
    
return true;
}

 

转载于:https://www.cnblogs.com/feiyucq/archive/2009/08/11/1543842.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值