#Include <GUIListView.au3>
#Include <ListViewConstants.au3>
#Include <WindowsConstants.au3>
#Include <WinAPIEx.au3>
Global Const $sProcess = 'firefox.exe'
Global $hListView, $PID = 0, $Prev1 = 0, $Prev2 = 0
GUICreate('MyGUI', 384, 200, -1, -1, -1, $WS_EX_TOPMOST)
GUICtrlCreateListView('| | | ', 10, 10, 364, 180, BitOR($LVS_DEFAULT, $LVS_NOSORTHEADER), $WS_EX_CLIENTEDGE)
$hListView = GUICtrlGetHandle(-1)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))
_GUICtrlListView_SetColumn($hListView, 0, 'Process', 140)
_GUICtrlListView_SetColumn($hListView, 1, 'PID', 52)
_GUICtrlListView_SetColumn($hListView, 2, 'CPU, %', 52, 1)
_GUICtrlListView_SetColumn($hListView, 3, 'Memory', 74, 1)
GUISetState()
_Update()
AdlibRegister('_Update', 500)
Do
Until GUIGetMsg() = -3
Func _Update()
Local $ID, $Mem, $Time1, $Time2
$ID = ProcessExists($sProcess)
If $ID Then
$Time1 = _WinAPI_GetProcessTimes($ID)
$Time2 = _WinAPI_GetSystemTimes()
If (IsArray($Time1)) And (IsArray($Time2)) Then
$Time1 = $Time1[1] + $Time1[2]
$Time2 = $Time2[1] + $Time2[2]
If ($Prev1) And ($Prev2) And ($PID = $ID) Then
$Mem = _WinAPI_GetProcessMemoryInfo($PID)
If Not _GUICtrlListView_GetItemCount($hListView) Then
_GUICtrlListView_AddItem($hListView, '')
_GUICtrlListView_AddSubItem($hListView, 0, '', 1)
_GUICtrlListView_AddSubItem($hListView, 0, '', 2)
_GUICtrlListView_AddSubItem($hListView, 0, '', 3)
EndIf
_SetText(_WinAPI_GetProcessName($PID), 0)
_SetText($PID, 1)
_SetText(Round(($Time1 - $Prev1) / ($Time2 - $Prev2) * 100), 2)
_SetText(_KB(Round($Mem[9] / 1024)), 3)
EndIf
$Prev1 = $Time1
$Prev2 = $Time2
$PID = $ID
Return
EndIf
EndIf
If _GUICtrlListView_GetItemCount($hListView) Then
_GUICtrlListView_DeleteAllItems($hListView)
EndIf
$Prev1 = 0
$Prev2 = 0
$PID = 0
EndFunc ;==>_Update
Func _KB($iSize)
If StringLen($iSize) > 3 Then
Return StringTrimRight($iSize, 3) & ',' & StringLeft($iSize, 3) & ' K'
EndIf
EndFunc ;==>_KB
Func _SetText($sText, $iIndex)
If StringCompare(_GUICtrlListView_GetItemText($hListView, 0, $iIndex), $sText, 1) Then
_GUICtrlListView_SetItemText($hListView, 0, $sText, $iIndex)
EndIf
EndFunc ;==>_SetText