Sign in to follow this  
Followers 0
lod3n

lod3nSTAT!

1 post in this topic

I've used Samurize in the past, but it's really overkill for my needs. And while you can pipe in console output from AutoIt, it's kind of a hassle.

So I wrote my own. I'm using PaulIA's GDI+ functions from Auto3Lib:

http://www.autoitscript.com/forum/index.php?showtopic=33677

So if you want to run this, you have to have Auto3Lib installed, plus the latest version of AutoIt.

You also have to download the attached canvas.png.

What the script does is load the entirely transparent canvas.png, and then repeatedly write text over the top of it, and then update the GUI to use the PNG as it's background. The text is supplied by a number of small system status functions. What this has going for it over Samurize is that it's running in AutoIt, so it's easy to extend the functions, and it has a Restart option in the tray menu. Make your change to the script file, select Restart from the tray menu, and your changes are immediately visible.

It's not without problems, for instance, using the canvas.png to draw on slows down the refresh considerably, and hits the CPU harder than I'd like, so I suggest running this at an interval that suits your system. 5 seconds works fine for me. I know there is a way to create a fresh image object to draw on without loading a file, but I don't know how to do it yet. Once I figure it out, I will post an update.

Another issue might be that it's too simplistic. One font, one color, one area. If you want something more complicated, and don't feel like adding it yourself, then Samurize is for you.

Enjoy. And again, thanks go to PaulIA for Auto3Lib.

Screenshot: post-14785-1184278300_thumb.jpg

Canvas.png REQUIRED: post-14785-1184278272_thumb.png

#include <A3LGDIPlus.au3>
#Include <Constants.au3>
#NoTrayIcon
Opt("MustDeclareVars", 0)

$font = "Tahoma"
$fontsize = 14
$fontStyle = 1 ;Add(+) these to change: 0: Normal, 1: Bold, 2: Italic, 4: Underline, 8: Strikethrough
$fontcolor = 0xFFFFFF ; RGB, 0xFFFFFF = White
$fontTrans = 255 ; 0-255 alpha transparancy

$shadowcolor = 0x000000  ; RGB, 0x000000 = Black
$shadowTrans = 255 ; 0-255 alpha transparancy - not working right. 0 = hidden, 1+ = shown
$shadowOffset = 2 ; how many pixels down and to the right should the shadow be?

$InfoUpdateEvery = 5 ; how many seconds between updates?
; I reccomend against setting this lower, my GDI usage is flawed, requiring a PNG canvas to
; draw on. I'd like to make a fresh transparent image in memory each redraw, but I don't know 
; how to yet.


; this function is called at the interval specified above
; it sets the text on the stats page
Func infoupdate()
    
    Local $data = ""
    $data &= @ComputerName & @CRLF
    $data &= "User: " & @LogonDomain &"\"& @UserName & @CRLF
    $data &= IPAddresses()
    $data &= DrivesUsage()
    $data &= PysicalRamUsage() & @CRLF
    $data &= CPULoad()
    
    updateText($data)
EndFunc

; here are a few system status functions to get you started:

Func CPULoad()
    ; only works if Task Manager is open - a non-WMI method would be nice
    If ProcessExists("taskmgr.exe") Then
        Return StatusbarGetText("Windows Task Manager", "", 2) & @CRLF
    Else
        Return ""
    EndIf
EndFunc

Func IPAddresses()
    Local $return = ""
    If (@IPAddress1 <> "0.0.0.0" And @IPAddress1 <> "127.0.0.1") Then $return &= "IP 1: " & @IPAddress1 & @CRLF
    If (@IPAddress2 <> "0.0.0.0") Then $return &= "IP 2: " & @IPAddress2 & @CRLF
    If (@IPAddress3 <> "0.0.0.0") Then $return &= "IP 3: " & @IPAddress3 & @CRLF
    If (@IPAddress4 <> "0.0.0.0") Then $return &= "IP 4: " & @IPAddress4 & @CRLF
    Return $return
EndFunc

Func DrivesUsage()
    Local $var = DriveGetDrive( "FIXED" )
    Local $output = ""
    If NOT @error Then
        For $i = 1 to $var[0]
            $drive = $var[$i]
            $cap = Round(DriveSpaceTotal($drive)/1024)
            $used = $cap - Round(DriveSpaceFree($drive)/1024)
            $percent = Round($used / $cap * 100) & "%"
            $output &= StringUpper($drive) & " " & $used &" / "&$cap & " GB (" & $percent & ") " & @CRLF
        Next
    EndIf
    Return $output 
EndFunc

Func PysicalRamUsage()
    Local $array = MemGetStats ( )
    Local $cap = Round($array[1]/1024)
    Local $used = $cap - Round($array[2]/1024)
    Local $percent = Round($used / $cap * 100) & "%"
    Return "RAM: " & $used &" / "&$cap & " GB (" & $percent & ")"
EndFunc




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; don't change anything beyond this point unless you're feeling adventurous
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

$title = "lod3nSTATS!"
$canvaspng = @ScriptDir & "\canvas.png"
$scriptcmdline = @AutoItExe & " " & $CmdLineRaw

; verify requirements, so I don't have to troubleshoot obvious stuff...

If Not @AutoItVersion >= "3.2.4.9" Then
    MsgBox(16,$title & " Error","AutoIt too old" &@CRLF&@CRLF& "Please make sure you have version 3.2.4.9 or later of AutoIt installed.")
    Exit
EndIf

If Not FileExists($canvaspng) Then
    MsgBox(16,$title & " Error","Missing canvas.png" &@CRLF&@CRLF& "Make sure you've copied it to the same folder as the script")
    Exit
EndIf

If Not @Compiled Then 
    
    If Not FileExists(@ProgramFilesDir&"\AutoIt3\Auto3Lib\Tools\BuildAPI.zip") Then
        MsgBox(16,$title & " Error","Missing Auto3Lib or Auto3Lib too old" &@CRLF&@CRLF& "Please download and install Auto3Lib by PaulIA, located aat the top of the Example Scripts forum")
        Exit
    EndIf

    If StringInStr($scriptcmdline,"beta") Then
        MsgBox(16,$title & " Error","Running in AutoIt Beta Mode" &@CRLF&@CRLF& _ 
        "This script requires the Auto3Lib by PaulIA, which does not work in Beta mode." &@CRLF&@CRLF& _ 
        "Please execute "&$title&" in AutoIt production mode")
        Exit
    EndIf

EndIf



_GDIP_StartUp()

; delcare constants
Global Const $AC_SRC_ALPHA      = 1
Global Const $ULW_ALPHA         = 2
Global Const $WS_EX_NOACTIVATE = 0x8000000

; declare GDI+ variables and structures
Global $hBitmap, $hImage, $hGraphic, $hFamily, $hFont, $tLayout, $hFormat, $aInfo, $hBrush1, $hBrush2, $iWidth, $iHeight, $hPen
Global $hImage   = _GDIP_ImageLoadFromFile($canvaspng)

;Global $hBitmap = _GDIP_BitmapCreateHBITMAPFromBitmap($hImage)

Global $width =  _GDIP_ImageGetWidth ($hImage)
Global $height = _GDIP_ImageGetHeight($hImage)
Global $newWidth = $width
Global $newHeight = $height
Global $hGraphic = _GDIP_ImageGetGraphicsContext($hImage)
Global $hFamily  = _GDIP_FontFamilyCreate($font)
Global $hFont    = _GDIP_FontCreate($hFamily, $fontsize, $fontStyle)
Global $hFormat  = _GDIP_StringFormatCreate(0)
Global $tLayout1  = _GDIP_RectFCreate($shadowOffset, $shadowOffset)
Global $hBrush1  = _GDIP_BrushCreateSolid(BitOR($shadowcolor,BitShift ($shadowTrans,-24)))
Global $tLayout2  = _GDIP_RectFCreate(0, 0)
Global $hBrush2  = _GDIP_BrushCreateSolid(BitOR($fontcolor,0xFF000000))




$style = BitOR($WS_POPUP,$WS_EX_NOACTIVATE)
$exstyle = BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW)
$GUI = GUICreate($title, $width, $height,@DesktopWidth-$width,0, $style, $exstyle)
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 

; pin to desktop, so it will survive winkey-d, or the Show Desktop shortcut
Opt("WinTitleMatchMode", 4)
DllCall("user32.dll", "int", "SetParent", "hwnd", $GUI, "hwnd", WinGetHandle("classname=Progman"))

GUISetState(@SW_SHOW)


infoupdate()
AdlibEnable ( "infoupdate" , $InfoUpdateEvery * 1000 )


Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

$infoitem = TrayCreateItem("Restart")
TrayItemSetOnEvent(-1,"RestartScript")

TrayCreateItem("")

$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ExitScript")

TraySetState()

While 1
    Sleep(10)   ; Idle loop
WEnd

Func RestartScript()
    Run($scriptcmdline)
    ExitScript()
    ;MsgBox(16,"Error - Not Yet Implemented",@AutoItExe & @CRLF & $CmdLineRaw )
EndFunc

Func ExitScript()
    ; Free resources
    _GDIP_PenDispose         ($hPen    )
    _GDIP_BrushDispose       ($hBrush1 )
    _GDIP_BrushDispose       ($hBrush2 )
    _GDIP_StringFormatDispose($hFormat )
    _GDIP_FontDispose        ($hFont   )
    _GDIP_FontFamilyDispose  ($hFamily )
    _GDIP_GraphicsDispose    ($hGraphic)
    _GDIP_ImageDispose       ($hImage  )
    _GDIP_ShutDown()
    
    Exit
EndFunc


Func _SetWindowStyle($hwnd,$style,$exstyle)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hwnd, "int", -16, "long", $style)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hwnd, "int", -20, "long", $exstyle)
EndFunc


Func updateText($text)
    ;$hGraphic = _GDIP_ImageGetGraphicsContext($hImage)
    _GDIP_GraphicsClear($hGraphic, 0x00000000)

    $aInfo1    = _GDIP_GraphicsMeasureString($hGraphic, $text, $hFont, $tLayout1, $hFormat)
    _GDIP_GraphicsDrawStringEx($hGraphic, $text, $hFont, $aInfo1[0], $hFormat, $hBrush1)

    $aInfo2   = _GDIP_GraphicsMeasureString($hGraphic, $text, $hFont, $tLayout2, $hFormat)
    _GDIP_GraphicsDrawStringEx($hGraphic, $text, $hFont, $aInfo2[0], $hFormat, $hBrush2)
    
    $newWidth   = DllStructGetData($aInfo1[0], "Width" )+$shadowOffset
    $newHeight  = DllStructGetData($aInfo1[0], "Height")+$shadowOffset
    
    SetBitMap($GUI, $hImage, $fontTrans)
    ;PushDown($gui)
EndFunc




Func RestoreWindow()
    If ($width <> $newWidth) Or ($width <> $newWidth) Then
        $width = $newWidth
        $height = $newHeight
        WinMove($gui,"",@DesktopWidth-$width,0,$width,$height)
    EndIf   
EndFunc


Func SetBitmap($hGUI, $hImage, $iOpacity)
  
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  $hScrDC  = _API_GetDC(0)
  $hMemDC  = _API_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIP_BitmapCreateHBITMAPFromBitmap($hImage,0x00000000) ; this is so SLOW! like half a second!
  $hOld    = _API_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity    )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  

  DllStructSetData($tSize, "X", _GDIP_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIP_ImageGetHeight($hImage))
    
  _API_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  RestoreWindow()
  _API_ReleaseDC   (0, $hScrDC)
  _API_SelectObject($hMemDC, $hOld)
  _API_DeleteObject($hBitmap)
  _API_DeleteDC    ($hMemDC)
  sleep(1000)
  
EndFunc

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites



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
Sign in to follow this  
Followers 0