#include "psapi.h" Psapi.lib BOOL FindProcess( DWORD dwProcessId ) { HWND hWnd = ::GetDesktopWindow(); HWND hTmpWnd = NULL; BOOL bFoundWnd = FALSE; DWORD dwPID; CRect rcC; while ( hWnd != NULL && !bFoundWnd ) { hTmpWnd = hWnd; hWnd = ::GetWindow( hWnd, GW_CHILD ); if ( hWnd ) { ::GetWindowThreadProcessId( hWnd, &dwPID ); if ( dwPID == dwProcessId ) if ( ::IsWindow( hWnd ) && ::IsWindowVisible( hWnd ) ) bFoundWnd = TRUE; } else { hWnd = hTmpWnd; hWnd = ::GetWindow( hWnd, GW_HWNDNEXT ); if ( hWnd ) { ::GetWindowThreadProcessId( hWnd, &dwPID ); WINDOWINFO pwi; memset( &pwi, 0x00, sizeof( pwi )); pwi.cbSize = sizeof( pwi ); ::GetWindowInfo( hWnd, &pwi); if ( dwPID == dwProcessId ) if ( ::IsWindow( hWnd ) && ::IsWindowVisible( hWnd ) ) bFoundWnd = TRUE; } else { hWnd = hTmpWnd; hWnd = ::GetParent( hWnd ); if ( hWnd ) { BOOL bFoundBranch = FALSE; while ( !bFoundBranch && !bFoundWnd && hWnd ) { hTmpWnd = hWnd; hWnd = ::GetWindow( hWnd, GW_HWNDNEXT ); if ( hWnd ) { bFoundBranch = TRUE; ::GetWindowThreadProcessId( hWnd, &dwPID ); if ( dwPID == dwProcessId ) if ( ::IsWindow( hWnd ) && ::IsWindowVisible( hWnd ) ) bFoundWnd = TRUE; } else { hWnd = hTmpWnd; hWnd = ::GetParent( hWnd ); } } } } } } return TRUE; }