1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
bool __stdcall EnumWindowsCallBack(HWND hWnd, LPARAM lParam) {
if(!hWnd) return false;
if(GetWindowLong(hWnd, GWL_HWNDPARENT)) return true ;
if(!IsWindowVisible(hWnd)) return true ;
DWORD pid ;
if(!GetWindowThreadProcessId(hWnd,&pid)) return true ;
PROCESSENTRY32 processEntry32 ;
processEntry32.dwSize = sizeof(PROCESSENTRY32);
HANDLE toolhelp32Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
char szExeFile[MAX_PATH];
bool finished = Process32First(toolhelp32Snapshot, &processEntry32) ;
while(finished) {
if(processEntry32.th32ProcessID==pid) {
strcpy(szExeFile,processEntry32.szExeFile);
break ;
}
finished = Process32Next(toolhelp32Snapshot, &processEntry32);
}
CloseHandle(toolhelp32Snapshot);
AnsiString lastring((char*)(((void**)lParam)[0])) ;
if(lastring.AnsiCompareIC(AnsiString(szExeFile))) return true;
((void**)lParam)[1] = hWnd ;
return false ;
}
void lanceAppli(AnsiString chemin) {
ShellExecute(0, NULL, chemin.c_str(), NULL, NULL, SW_SHOWNORMAL);
}
void chercheWin(AnsiString chemin) {
void* pReturn[2] ;
pReturn[0] = (void*) chemin.c_str() ;
pReturn[1] = NULL ;
EnumWindows((WNDENUMPROC)EnumWindowsCallBack, (LPARAM)pReturn);
if(IsWindow(pReturn[1])) {
// YES !!! (HWND)pReturn[1] est la bonne window !!
}
} |
Partager