Tu peux regarder ce script:
Apparemment, tu crées ca au début du script, ca sert de vérification pour savoir si on a une icône ou pas. Parce que si on en a pas, on en mets une générique
Code : Tout sélectionner
$dummy = GUICtrlCreateIcon("", 0, 0, 0)
GUICtrlSetState($dummy, $GUI_HIDE)
Puis tu fais comme ca:
En renseignant le Pid du programme.
Code : Tout sélectionner
$fName = _WinAPI_ProcessGetFilename($p_pid, True)
$setImage = GUICtrlSetImage($dummy, $fName)
If $setImage = 1 Then
$hImageIndex = _GUIImageList_AddIcon($hImage, $fName, 0)
Else
$hImageIndex = _GUIImageList_AddIcon($hImage, "shell32.dll", 2)
EndIf
_GUICtrlListView_SetItemImage($hListview, $hLV_i, $hImageIndex, 0)
Code : Tout sélectionner
Func _WinAPI_ProcessGetFilename($vProcessID, $bFullPath = False)
; Not a Process ID? Must be a Process Name
If Not IsNumber($vProcessID) Then
$vProcessID = ProcessExists($vProcessID)
; Process Name not found (or invalid parameter?)
If $vProcessID == 0 Then Return SetError(1, 0, "")
EndIf
Local $hProcess, $stFilename, $aRet, $sFilename, $sDLLFunctionName
; Since the parameters and returns are the same for both of these DLL calls, we can keep it all in one function
If $bFullPath Then
$sDLLFunctionName = "GetModuleFileNameEx"
Else
$sDLLFunctionName = "GetModuleBaseName"
EndIf
; Get process handle (lod3n)
Local $hProcess = DllCall("kernel32.dll", "ptr", "OpenProcess", "int", BitOR(0x400, 0x10), "int", 0, "int", $vProcessID)
If @error Or Not IsArray($hProcess) Then Return SetError(2, 0, "")
; Create 'receiving' string buffers and make the call
$stFilename = DllStructCreate("wchar[32767]")
$aRet = DllCall("psapi.dll", "dword", $sDLLFunctionName & "W", "ptr", $hProcess[0], "ptr", Chr(0), "ptr", DllStructGetPtr($stFilename), "dword", 32767)
; Error from either call? Cleanup and exit with error
If @error Or Not IsArray($aRet) Then
; Close the process handle
DllCall("kernel32.dll", "ptr", "CloseHandle", "ptr", $hProcess[0])
; DLLStructDelete()'s:
$stFilename = 0
$hProcess = 0
Return SetError(2, 0, "")
EndIf
;$aRet[0] = size of string copied over, minus null-terminator
;$stFilename should now contain either the filename or full path string (based on $bFullPath)
$sFilename = DllStructGetData($stFilename, 1)
DllCall("kernel32.dll", "ptr", "CloseHandle", "ptr", $hProcess[0])
; DLLStructDelete()'s
$stFilename = 0
$hProcess = 0
Return SetError(0, 0, $sFilename)
EndFunc ;==>_WinAPI_ProcessGetFilename