枚举当前打开的所有窗口

#include <Stdio.h>

#include <Windows.h>

 

BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam);

 

int main( int argc, char* argv[] )

{

     EnumWindows( EnumWindowsProc, NULL );

     return 0;

}

 

HWND m_hwndFind[1000] = {0};

int  m_num = 0;

 

 

BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)

{

     if(::GetWindowLong(hWnd,GWL_STYLE) & WS_VISIBLE)

     {

         char sBuf[256];

 

         //获取窗口标题

         ::GetWindowText( hWnd, sBuf, 256 );

         if ( strcmp( sBuf, "我的电脑" ) == 0 )

         {

              //在发现我的电脑时设置其标题为www.a3gs.com

              ::SetWindowText( hWnd, "www.a3gs.com" );

         }

         printf( "%s\n", sBuf );

         m_hwndFind[m_num] = hWnd;

         m_num++;

     }

     return 1;

}

你可能感兴趣的:(枚举)