cs_Esquisse
Messages postés77Date d'inscriptionsamedi 28 décembre 2002StatutMembreDernière intervention20 juillet 2005
-
24 oct. 2003 à 17:58
cs_Esquisse
Messages postés77Date d'inscriptionsamedi 28 décembre 2002StatutMembreDernière intervention20 juillet 2005
-
27 oct. 2003 à 19:49
Salut ;)
Voila par exemple j'ai winamp de lancé donc je recup son hwnd, titre de fenetre et nom de tache mais j'arrive pas a récuperer le nom de l'executable cad :
cs_Esquisse
Messages postés77Date d'inscriptionsamedi 28 décembre 2002StatutMembreDernière intervention20 juillet 2005 24 oct. 2003 à 20:22
Merci pour une réponse aussi rapide mais ca m'aide pas trop :/
En fait, grace à toi, je trouve les noms des exe lancés... Mais je ne voit pas comment trouver un lien entre les api de process vers ceux de fenetres (ceux que j'ai : handle, Nom fenetre, ID app)...
Car dans les process comme c ecrit dans la MSDN ce sont des pseudohandle et (forcement) ils correspondent pas aux handle des fenetres.
Qqu'un connait une fonction qui pourrait faire le rapprochement entre un process et un handle (ou une autre voie de recherche) ?
cs_Esquisse
Messages postés77Date d'inscriptionsamedi 28 décembre 2002StatutMembreDernière intervention20 juillet 2005 26 oct. 2003 à 14:14
grr ca marche toujours pas. je doit pas être loin mais ca renvoie toujours c:\program files\...\vb6.exe :'(
Je mets un bout de code commenté et simplifié pour savoir ou est-ce que je fait une erreur (note faut que winamp 3.x soit lancer pour recup le hwnd) :
'Mes déclarations dans un module :
'Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
'Public Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
'Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'Public Const GWL_HINSTANCE = (-6)
'Le code
Dim ModuleName As String
Dim FileName As String
Dim hInst As Long
Dim WinAMPHwnd As Long
'Je récupe le hwnd de Winamp
WinAMPHwnd = FindWindow("STUDIO", vbNullString)
cs_Esquisse
Messages postés77Date d'inscriptionsamedi 28 décembre 2002StatutMembreDernière intervention20 juillet 2005 26 oct. 2003 à 19:08
euh aucun rapport avec ce dont j'ai besoin... Winamp est un exemple de programme (je ne sias pas quel prog ca peut-être... j'ai mit Winamp pour mon exemple)
cs_Esquisse
Messages postés77Date d'inscriptionsamedi 28 décembre 2002StatutMembreDernière intervention20 juillet 2005 27 oct. 2003 à 19:49
J'ai trouvé la solution :)
Je la mets au cas ou ca peux aider qqu'un :)
Dans un module :
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function CreateToolhelp32Snapshot Lib "Kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Declare Function Process32First Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function Process32Next Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long)
Public Const TH32CS_SNAPHEAPLIST = &H1
Public Const TH32CS_SNAPPROCESS = &H2
Public Const TH32CS_SNAPTHREAD = &H4
Public Const TH32CS_SNAPMODULE = &H8
Public Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Public Const TH32CS_INHERIT = &H80000000
Public Const MAX_PATH As Integer = 260
Public Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Code :
Dim ModuleName As String
Dim FileName As String
Dim hInst As Long
Dim WinAMPHwnd As Long
Dim ProcessID As Long
Dim hSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim r As Boolean
'Je récupe le hwnd de Winamp
WinAMPHwnd = FindWindow("STUDIO", vbNullString)
GetWindowThreadProcessId WinAMPHwnd, ProcessID
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
r = Process32First(hSnapShot, uProcess)
Do While r
If ProcessID = uProcess.th32ProcessID Then
FileName = Left$(uProcess.szExeFile, IIf(InStr(1, uProcess.szExeFile, Chr$(0)) > 0, InStr(1, uProcess.szExeFile, Chr$(0)) - 1, 0))
Exit Do
End If
r = Process32Next(hSnapShot, uProcess)
Loop