Jump to content

Recommended Posts

Posted (edited)

Screenshot-1.png

I am trying to insert the free RAM and the use of the CPU in % on the bar of the Total Commander title I have arrived so far but instead of the % reports to me in numbers where I am wrong?

#include <Process.au3>
#NoTrayIcon
Func MemGetTotalPhys()
Local $st_MemInfo = DllStructCreate("dword;dword;dword;dword;dword;dword")
Local $a_Return = DllCall("Kernel32.dll", "BOOL", "GlobalMemoryStatusEx", "struct*", $st_MemInfo)
If Not $a_Return[0] Then Return SetError(1, 0, 0)
Return DllStructGetData($st_MemInfo, 1)
EndFunc

Func ProcessCPUUsage($PID)
Local $st_CPU1, $st_CPU2, $st_System, $st_Time1, $st_Time2
$st_System = DllCall("Kernel32.dll", "handle", "OpenProcess", "dword", BitOR(0x0400, 0x0800), "int", False, "int", $PID)
If @error Or Not $st_System[0] Then Return SetError(1, 0, -1)
$st_Time1 = DllStructCreate("uint;dword")
$st_CPU1 = DllStructCreate("uint[10]")
DllCall("Kernel32.dll", "int", "GetProcessTimes", "handle", $st_System[0], "ptr", DllStructGetPtr($st_Time1), "ptr", DllStructGetPtr($st_Time1), "ptr", DllStructGetPtr($st_CPU1), "ptr")
Sleep(200)
$st_Time2 = DllStructCreate("uint;dword")
$st_CPU2 = DllStructCreate("uint[10]")
DllCall("Kernel32.dll", "int", "GetProcessTimes", "handle", $st_System[0], "ptr", DllStructGetPtr($st_Time2), "ptr", DllStructGetPtr($st_Time2), "ptr", DllStructGetPtr($st_CPU2), "ptr")
DllCall("Kernel32.dll", "int", "CloseHandle", "handle", $st_System[0])
Local $lDelta = (DllStructGetData($st_Time2, 2) - DllStructGetData($st_Time1, 2)) / 10000, $lKernel = (DllStructGetData($st_CPU2, 1) - DllStructGetData($st_CPU1, 1)) / $lDelta, $lUser = (DllStructGetData($st_CPU2, 2) - DllStructGetData($st_CPU1, 2)) / $lDelta
Return $lKernel + $lUser
EndFunc

Func MemGetFreePhys()
Local $st_MemInfo = DllStructCreate("dword;dword;dword;dword;dword;dword")
Local $a_Return = DllCall("Kernel32.dll", "BOOL", "GlobalMemoryStatusEx", "struct*", $st_MemInfo)
If Not $a_Return[0] Then Return SetError(1, 0, 0)
Return DllStructGetData($st_MemInfo, 4)
EndFunc

Func GetTotalMemory()
    Local $memoryInfo = MemGetStats()
    Return $memoryInfo[1]
EndFunc

Func GetFreeMemory()
    Local $memoryInfo = MemGetStats()
    Return $memoryInfo[2]
EndFunc

; Run Total Commander executable
Run(@ScriptDir & '\TOTALCMD64.EXE')
Sleep(100)

; Define constants for Total Commander's window class and new title
Local $TTOTAL_CMD_class = "[CLASS:TTOTAL_CMD]"
Local $TTOTAL_CMD_windows_new_title = "TC UltraPack X64"

; Check if a Total Commander window exists
If WinExists($TTOTAL_CMD_class) Then
    Local $TTOTAL_CMD_windows_array
    Local $version = IniRead(@ScriptDir & "\version.ini", "Setup", "Version", "Default Value")
    ;Local $version = FileReadLine(@ScriptDir & "\version.ini", 1)
    Local $new_title_with_version = $TTOTAL_CMD_windows_new_title & " v" & $version

    ; Set the title for all Total Commander windows
    WinSetTitle($TTOTAL_CMD_class, '', $new_title_with_version)

    ; Get the process ID of the Total Commander window
    $process_id = WinGetProcess(WinGetHandle($TTOTAL_CMD_class))

    ; Continuously update the title for new Total Commander windows
    While WinExists($TTOTAL_CMD_class)
        Sleep(1000) ; wait for 1 second
        $TTOTAL_CMD_windows_array = WinList($TTOTAL_CMD_class)

        If IsArray($TTOTAL_CMD_windows_array) Then
            For $i = 1 To UBound($TTOTAL_CMD_windows_array) - 1
                ; Check if the window belongs to the Total Commander process
                If WinGetProcess($TTOTAL_CMD_windows_array[$i][1]) = $process_id Then
                    ; Get the list of all drive letters in use
                    $drives = DriveGetDrive("ALL")
                    $new_title_with_space = $new_title_with_version & " - Drives free Space: "
                    For $j = 1 To $drives[0]
                        ; Get the free space on the drive in percentage
                        $free_space = DriveSpaceFree($drives[$j]) / DriveSpaceTotal($drives[$j]) * 100
                        $new_title_with_space &= StringUpper($drives[$j]) & " (" & Round($free_space, 2) & "%), "
                    Next
                    $new_title_with_space = StringTrimRight($new_title_with_space, 2) ; remove the trailing comma and space
                    ; Add CPU and RAM usage to the window title
                    $cpu_usage = Round(100 * ProcessCPUUsage($process_id), 2)
                    $ram_free = Round(100 * GetFreeMemory() / GetTotalMemory(), 2)
                    $new_title_with_space &= " | RAM free: " & $ram_free & "% | CPU: " & $cpu_usage & "%"
                    If WinGetTitle($TTOTAL_CMD_windows_array[$i][1]) <> $new_title_with_space Then
                        WinSetTitle($TTOTAL_CMD_windows_array[$i][1], '', $new_title_with_space)
                    EndIf
                EndIf
            Next
        EndIf
    WEnd
EndIf

Thank you

Edited by erik501

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...