#include #include #include #include #include #include #OnAutoItStartRegister "_ScriptRestart" _Singleton('_TinyCPU') ;size of cpu bar,color,update speed Global $g_iCpuBarHeight = 2, $g_iCpuBarColor = 0xFF00ACFF, $g_iUpdateSpeedMS = 750 Global $g_iStartHeight = _GetDesktopHeight() ;Create small gui (cpu bar) just above taskbar Global $g_hGUI = GUICreate('TinyCPU', @DesktopWidth, $g_iCpuBarHeight, 0, $g_iStartHeight - $g_iCpuBarHeight, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_LAYERED)) GUISetState(@SW_SHOW) _WinAPI_SetLayeredWindowAttributes($g_hGUI, 0xABCDEF) ;Set gui transparent ;Start GDIPlus, create graphics and pen _GDIPlus_Startup() Global $g_hGraphic = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) Global $g_hPen = _GDIPlus_PenCreate($g_iCpuBarColor, $g_iCpuBarHeight * 2) _GDIPlus_GraphicsClear($g_hGraphic, 0xFFABCDEF) AdlibRegister(_TinyCPUUpdate, $g_iUpdateSpeedMS) ;Register release of gdiplus objects and timer OnAutoItExitRegister(_Release) ;endless sleep While Sleep(60000) WEnd Func _TinyCPUUpdate() Local Static $aCpuEnd, $aCpuStart = _CPUCalc(), $hDesktop = _GetDesktopHandle(), $nCleared = False, $iCounter = 0 ;Get latest cpu times $aCpuEnd = _CPUCalc() ;calculate difference between start and end times Local $fCPU = _CPUCalc($aCpuStart, $aCpuEnd) ;copy last cpu times to start. $aCpuStart = $aCpuEnd ;Get Foregrond(active) window handle Local $hForeGround = _WinAPI_GetForegroundWindow() ;Check if active window (excluding desktop) is full screen. Dont want cpu bar showing while watching a movie or something.. If ($hForeGround <> $hDesktop) And _IsFullScreen($hForeGround) Then ;keep track if bar is already clear (hidden). This avoids reclearing bar when its alreaady clear but also works as ;an indicator to if a window was just previously in full screen If Not $nCleared Then ;clear bar and set flag _GDIPlus_GraphicsClear($g_hGraphic, 0xFFABCDEF) $nCleared = True EndIf ;make sure cpu value is valid. ElseIf $fCPU <= 1 Then ;Ensure gui is on top of z order every few loops or when a window exits full screen. If $nCleared Or $iCounter >= 5 Then DllCall('user32.dll', 'int', 'BringWindowToTop', 'hwnd', $g_hGUI) If Not WinExists($hDesktop) Then $hDesktop = _GetDesktopHandle() ; ensure desktop handle still valid If $g_iStartHeight <> _GetDesktopHeight() Then _ScriptRestart() ; screen dimensions changed $iCounter = 0 EndIf ;Update CPU bar _GDIPlus_GraphicsClear($g_hGraphic, 0xFFABCDEF) _GDIPlus_GraphicsDrawLine($g_hGraphic, 0, 0, Round(@DesktopWidth * $fCPU), 0, $g_hPen) ;Update counter and Flags $nCleared = False $iCounter += 1 EndIf EndFunc ;==>_TinyCPUUpdate Func _CPUCalc($aCpuStart = 0, $aCpuEnd = 0) If Not @NumParams Then Local $aRet = DllCall('Kernel32.dll', "int", "GetSystemTimes", 'uint64*', 0, 'uint64*', 0, 'uint64*', 0) Local $aCpuTime[2] = [$aRet[1], ($aRet[2] + $aRet[3])] ; [idle, user+kernel] Return $aCpuTime Else Local $iIdle = $aCpuEnd[0] - $aCpuStart[0] Local $iSystem = $aCpuEnd[1] - $aCpuStart[1] ; Return ($iSystem - $iIdle) / $iSystem EndIf EndFunc ;==>_CPUCalc Func _IsFullScreen($hWnd) If Not IsHWnd($hWnd) Then Return False Local $tR = _WinAPI_GetWindowRect($hWnd) Return ($tR.Bottom >= @DesktopHeight And $tR.Right >= @DesktopWidth And $tR.Left <= 0 And $tR.Top <= 0) ? True : False EndFunc ;==>_IsFullScreen Func _GetDesktopHeight() Local $tDH = DllCall("user32.dll", "bool", "SystemParametersInfoW", "uint", 0x0030, "uint", 0, "struct*", DllStructCreate($tagRECT), "uint", 0)[3] Return $tDH.Bottom EndFunc ;==>_GetDesktopHeight ;http://www.autoitscript.com/forum/topic/119783-desktop-class-workerw Func _GetDesktopHandle() Local $aWinList, $hSHELLDLL_DefView, $aClass[3] = ['[CLASS:Progman]', '[CLASS:WorkerW]', ''] For $i = 0 To 2 $aWinList = WinList($aClass[$i]) For $j = 1 To $aWinList[0][0] $hSHELLDLL_DefView = ControlGetHandle($aWinList[$j][1], '', '[CLASS:SHELLDLL_DefView; INSTANCE:1]') If Not @error Then If ControlGetHandle($hSHELLDLL_DefView, '', '[CLASS:SysListView32; INSTANCE:1]') Then Return $aWinList[$j][1] EndIf Next Next Return SetError(1, 0, 0) EndFunc ;==>_GetDesktopHandle Func _Release() _GDIPlus_PenDispose($g_hPen) _GDIPlus_GraphicsDispose($g_hGraphic) _GDIPlus_Shutdown() EndFunc ;==>_Release ; #FUNCTION# ==================================================================================================================== ; Author.........: Yashied ; Modified.......: Beege ; Remarks........: Requires #OnAutoItStartRegister "_ScriptRestart" ; =============================================================================================================================== Func _ScriptRestart() Local Static $bStartup = True If $bStartup Then Sleep(50) Local $Pid = ConsoleRead(1) If @extended Then While ProcessExists($Pid) Sleep(50) WEnd EndIf $bStartup = False Else StdinWrite(Run((@Compiled ? @ScriptFullPath : @AutoItExe) & ' ' & $CmdLineRaw, @ScriptDir, Default, 1), @AutoItPID) Exit EndIf EndFunc ;==>_ScriptRestart