Process ID 로 HWND 찾아내기 Posted by 빵빵빵 2009/06/11 16:47 전산(컴퓨터)/PC-Windows 전산(컴퓨터)/PC-Windows #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; } 2009/06/11 16:47 2009/06/11 16:47 Tags HWND, Process ID, ProcessID Trackback: 0 Comment: 0 이 글에는 트랙백을 보낼 수 없습니다