#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $IDLETIME, $KERNELTIME, $USERTIME
Global $StartIdle, $StartKernel, $StartUser
Global $EndIdle, $EndKernel, $EndUser
Global $Timer
Dim $HDDDRV,$HDDSP1,$HDDSP2,$HDDSP3,$HDDSP4,$HDDSP5,$HDDSP6
$HDDDRV = DriveGetDrive( "FIXED" )
Dim $HDD[6]
$IDLETIME = DllStructCreate('dword;dword')
$KERNELTIME = DllStructCreate('dword;dword')
$USERTIME = DllStructCreate('dword;dword')
$hGUI = GUICreate('System Info', 200, 100+20*$HDDDRV[0], -1, -1, -1, $WS_EX_TOPMOST)
GUISetIcon('shell32.dll', 13)
GUICtrlCreateLabel('CPU Usage:', 25, 20, 105, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
$ValueLabel = GUICtrlCreateLabel('', 130, 20, 40, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
GUICtrlCreateLabel('Memory Usage:', 25, 40, 105, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
$Mem = GUICtrlCreateLabel('000', 130, 40, 40, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
If $HDDDRV[0] >= 1 Then
GUICtrlCreateLabel(StringUpper('Free Space ' & $HDDDRV[1]), 25, 40+20*1, 105, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
$HDDSP1= GUICtrlCreateLabel('000', 130, 40+20*1, 40, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
EndIf
If $HDDDRV[0] >= 2 Then
GUICtrlCreateLabel(StringUpper( 'Free Space ' & $HDDDRV[2]), 25, 40+20*2, 105, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
$HDDSP2= GUICtrlCreateLabel('000', 130, 40+20*2, 40, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
EndIf
If $HDDDRV[0] >= 3 Then
GUICtrlCreateLabel(StringUpper('Free Space ' & $HDDDRV[3]), 25, 40+20*3, 105, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
$HDDSP3= GUICtrlCreateLabel('000', 130, 40+20*3, 40, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
EndIf
If $HDDDRV[0] >= 4 Then
GUICtrlCreateLabel(StringUpper('Free Space ' & $HDDDRV[4]), 25, 40+20*4, 105, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
$HDDSP4= GUICtrlCreateLabel('000', 130, 40+20*4, 40, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
EndIf
If $HDDDRV[0] >= 5 Then
GUICtrlCreateLabel(StringUpper('Free Space ' & $HDDDRV[5]), 25, 40+20*5, 105, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
$HDDSP5= GUICtrlCreateLabel('000', 130, 40+20*5, 40, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
EndIf
If $HDDDRV[0] >= 6 Then
GUICtrlCreateLabel(StringUpper('Free Space ' & $HDDDRV[6]), 25, 40+20*6, 105, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
$HDDSP6= GUICtrlCreateLabel('000', 130, 40+20*6,40, 20)
GUICtrlSetFont(-1, 8.5, 800, Default, 'MS Sans Serif')
EndIf
$StartButton = GUICtrlCreateButton('Start', 10, 60+20*$HDDDRV[0], 75, 23)
$StopButton = GUICtrlCreateButton('Stop', 115, 60+20*$HDDDRV[0], 75, 23)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()
_GetSysTime($StartIdle, $StartKernel, $StartUser)
$Timer = TimerInit()
GUICtrlSetState($StartButton, $GUI_DISABLE)
GUICtrlSetState($StopButton, $GUI_ENABLE)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $StartButton
_GetSysTime($StartIdle, $StartKernel, $StartUser)
$Timer = TimerInit()
GUICtrlSetState($StartButton, $GUI_DISABLE)
GUICtrlSetState($StopButton, $GUI_ENABLE)
Case $StopButton
GUICtrlSetState($StopButton, $GUI_DISABLE)
GUICtrlSetState($StartButton, $GUI_ENABLE)
GUICtrlSetData($ValueLabel, '')
EndSwitch
If BitAND(GUICtrlGetState($StopButton), $GUI_ENABLE) And TimerDiff($Timer) >= 1000 Then
$Mems = MemGetStats ( )
ControlSetText($hGUI, "",$Mem, $Mems[0] & "%")
_GetSysTime($EndIdle, $EndKernel, $EndUser)
_CPUCalc()
_GetSysTime($StartIdle, $StartKernel, $StartUser)
$Timer = TimerInit()
For $i=1 To $HDDDRV[0]
$HDD[$i]=Round(DriveSpaceFree($HDDDRV[$i])/1024,1) & "G"
Next
If $HDDDRV[0] >= 1 Then
GUICtrlSetData($HDDSP1,$HDD[1])
EndIf
If $HDDDRV[0] >= 2 Then
GUICtrlSetData($HDDSP2,$HDD[2])
EndIf
If $HDDDRV[0] >= 3 Then
GUICtrlSetData($HDDSP3,$HDD[3])
EndIf
If $HDDDRV[0] >= 4 Then
GUICtrlSetData($HDDSP4,$HDD[4])
EndIf
If $HDDDRV[0] >= 5 Then
GUICtrlSetData($HDDSP5,$HDD[5])
EndIf
If $HDDDRV[0] >= 6 Then
GUICtrlSetData($HDDSP6,$HDD[6])
EndIf
EndIf
Sleep(100)
WEnd
Func _GetSysTime(ByRef $sIdle, ByRef $sKernel, ByRef $sUser)
DllCall('kernel32.dll', 'int', 'GetSystemTimes', 'ptr', DllStructGetPtr($IDLETIME), _
'ptr', DllStructGetPtr($KERNELTIME), _
'ptr', DllStructGetPtr($USERTIME))
$sIdle = DllStructGetData($IDLETIME, 1)
$sKernel = DllStructGetData($KERNELTIME, 1)
$sUser = DllStructGetData($USERTIME, 1)
EndFunc ;==>_GetSysTime
Func _CPUCalc()
Local $iSystemTime, $iTotal, $iCalcIdle, $iCalcKernel, $iCalcUser
$iCalcIdle = ($EndIdle - $StartIdle)
$iCalcKernel = ($EndKernel - $StartKernel)
$iCalcUser = ($EndUser - $StartUser)
$iSystemTime = ($iCalcKernel + $iCalcUser)
$iTotal = Int(($iSystemTime - $iCalcIdle) * (100 / $iSystemTime)) & '%'
If GUICtrlRead($ValueLabel) <> $iTotal Then ControlSetText($hGUI, '', $ValueLabel, $iTotal)
EndFunc ;==>_CPUCalc