#include <Array.au3>
#include <WinAPI.au3>
Const $TH32CS_SNAPTHREAD = 4
Const $tagThread = "dword dwSize;dword cntUsage;dword th32ThreadID;" & _
"dword th32OwnerProcessID;long tpBasePri;" & _
"long tpDeltaPri;dword dwFlags"
$aThread = _EnumProcessThreads(@AutoItPid)
_ArrayDisplay($aThread)
Func _EnumProcessThreads($iProcessId)
Local $hSnapshot, $iThreadId, $iOwnerId, $tThread, $aResult[1]
$iProcessId = ProcessExists($iProcessId)
$tThread = _Thread32First($hSnapshot)
$hSnapshot = _CreateToolhelp32Snapshot(0, $TH32CS_SNAPTHREAD)
While True
_Thread32Next($hSnapshot, $tThread)
If @error Then ExitLoop
$iThreadId = DllStructGetData($tThread, "th32ThreadID")
$iOwnerId = DllStructGetData($tThread, "th32OwnerProcessID")
If $iOwnerId = $iProcessId Then
$aResult[Ubound($aResult) - 1] = $iThreadId
Redim $aResult[Ubound($aResult) + 1]
EndIf
WEnd
$tThread = 0
_WinAPI_CloseHandle($hSnapshot)
If Ubound($aResult) = 1 Then Return SetError(1, 0, 0)
Redim $aResult[Ubound($aResult) - 1]
Return SetError(0, Ubound($aResult), $aResult)
EndFunc ;==>_EnumProcessThreads()
Func _CreateToolhelp32Snapshot($iProcessId, $iFlag)
Local $hSnapshot
$iProcessId = ProcessExists($iProcessId)
$hSnapshot = DllCall("Kernel32.Dll", "hWnd", "CreateToolhelp32Snapshot", _
"dword", $iFlag, "int", $iProcessId)
Return $hSnapshot[0]
EndFunc ;==>_CreateToolhelp32Snapshot()
Func _Thread32First($hSnapshot)
Local $tThread, $pThread, $iResult
$tThread = DllStructCreate($tagThread)
$pThread = DllStructGetPtr($tThread)
DllStructSetData($tThread, 1, DllStructGetSize($tThread))
$iResult = DllCall("Kernel32.Dll", "int", "Thread32First", _
"hWnd", $hSnapshot, _
"ptr", $pThread)
Return SetError(Not $iResult[0], 0, $tThread)
EndFunc ;==>_Thread32First()
Func _Thread32Next($hSnapshot, ByRef $tThread)
Local $iResult
$iResult = DllCall("Kernel32.Dll", "int", "Thread32Next", _
"hWnd", $hSnapshot, _
"ptr", DllStructGetPtr($tThread))
Return SetError(Not $iResult[0], 0, $iResult[0])
EndFunc ;==>_Thread32Next()
|