Beege Posted February 13, 2010 Share Posted February 13, 2010 (edited) Here is the latest UDF that I have been working on. Its sort of a spin off from my other Graph UDF. Its for creating a scrolling bar graph as the tray icon. Its very similar to how the program ProcessExploror by sysinternals displays cpu history. Please let me know what you think, especially if you have any kind of problems. Thanks for looking. Example #include "TIG.au3" Opt('GuiOnEventMode', 1); Black Green Pink Yellow Blue Red Purple Orange Gray Local $Color, $Invert, $aColors[9] = [0xFF000000, 0xFF00FF00, 0xFFF004DE, 0xFFFFFF00, 0xFF00ACFF, 0xFFFF0000, 0xFF8000FF, 0xFFFF8000, 0xFFADADAD] Local $GUI = GUICreate('TrayIcon', 200, 50) GUISetOnEvent(-3, '_Exit', $GUI) GUISetState() _TIG_CreateTrayGraph(0, 1000) While 1 $Color = $aColors[Random(0,8,1)] $Invert = _Invert($Color) _TIG_SetBackGoundColor($Color) _TIG_SetBarColor($Invert) For $i = 0 To 16 _TIG_UpdateTrayGraph(Random(0, 1000, 1)) Sleep(100) Next WEnd Func _Exit() Exit EndFunc ;==>_Exit ;Returns Invert of ARGB value Func _Invert($iValue) Return '0x' & Hex(BitOR(0xFF000000,(0xFFFFFFFF-$iValue)),8) EndFunc UDF expandcollapse popup#Region Header ; #INDEX# ======================================================================================================================= ; Title .........: TIG ; AutoIt Version : 3.3.4.0 ; Language ......: English ; Description ...: Functions to create and update a tray icon scrolling bar graph ; Author(s) .....: Beege ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_TIG_CreateTrayGraph ;_TIG_SetBarColor ;_TIG_SetBackGoundColor ;_TIG_SetRange ;_TIG_UpdateTrayGraph ; =============================================================================================================================== #cs CallTips: _TIG_CreateTrayGraph($iMin = 0, $iMax = 100, $iBarColor = 0xFF00ACFF, $iBackColor = 0xFF000000) Default $iBarColor = Blue; $iBackColor = Black _TIG_SetBarColor($iBarColor = 0xFF00ACFF) Default $iBarColor = Blue _TIG_SetBackGoundColor($iBackColor = 0xFF000000) Default $iBackColor = Black _TIG_SetRange($iMin = 0, $iMax = 100) _TIG_UpdateTrayGraph($iValue) #ce #include <GDIPlus.au3> #include <WindowsConstants.au3> #EndRegion Header #Region Initialization AutoItWinSetTitle(AutoItWinGetTitle() & '_TraYIcoNUdF') #EndRegion Initialization #Region Global Variables and Constants Global Enum $g_hGUI, $g_hGraphics, $g_hBitmap, $g_hBuffer, $g_hPen, $g_iMin, $g_iMax, $g_iBackColor, $g_iBarColor, $g_hIcon, $g_sValues, $g_hShell32, $iMax Global $aTI[$iMax] $aTI[$g_hGUI] = WinGetHandle(AutoItWinGetTitle()) #cs $aTI[$g_hGUI] = Autoit Window Handle $aTI[$g_hGraphics] = Handle to Graphics object $aTI[$g_hBitmap] = Handle to Bitmap Object $aTI[$g_hBuffer] = Handle to Buffer $aTI[$g_hPen] = Handle to Pen Object $aTI[$g_iMin] = Minimum Y Range $aTI[$g_iMax] = Maximum Y Range $aTI[$g_iBackColor] = Background Color $aTI[$g_iBarColor] = Bar Color $aTI[$g_hIcon] = Handle to Icon Bitmap $aTI[$g_sValues] = String Containing Y Value History $aTI[$g_hShell32] = Handle to Shell32 dll #ce #EndRegion Global Variables and Constants #Region Public Functions ; #FUNCTION# ==================================================================================================================== ; Name...........: _TIG_CreateTrayGraph ; Description ...: Creates Tray Icon Bar Graph ; Syntax.........: _TIG_CreateTrayGraph($iMin = 0, $iMax = 100, $iBarColor = 0xFF00ACFF, $iBackColor = 0xFF000000) ; Parameters ....: $iMin - Minimum Y Value. Must Not be less than 0. ; $iMax - Maximum Y Value ; $iBarColor - Alpha, Red, Green and Blue Hex Value. (0xAARRGGBB). Default = Blue ; $iBackColor - Alpha, Red, Green and Blue Hex Value. (0xAARRGGBB). Default = Black ; Return values .: Success - 1 ; Failure - 0 and sets @ERROR: ; - 1 Minimum Value Less than zero ; - <> 0 - Value returned from _WinAPI_GetLastERROR() ; Author ........: Beege ; Remarks .......: ; =============================================================================================================================== Func _TIG_CreateTrayGraph($iMin = 0, $iMax = 100, $iBarColor = 0xFF00ACFF, $iBackColor = 0xFF000000) If $iMin < 0 Then Return SetError(1, @extended, 0) _GDIPlus_Startup() OnAutoItExitRegister('_GdiExit') If $iBarColor = -1 Or $iBarColor = Default Then $iBarColor = 0xFF00ACFF If $iBackColor = -1 Or $iBackColor = Default Then $iBackColor = 0xFF000000 If $iMin = -1 Or $iMin = Default Then $iMin = 0 If $iMax = -1 Or $iMax = Default Then $iMax = 100 $aTI[$g_hGraphics] = _GDIPlus_GraphicsCreateFromHWND($aTI[$g_hGUI]) $aTI[$g_hBitmap] = _GDIPlus_BitmapCreateFromGraphics(16, 16, $aTI[$g_hGraphics]) $aTI[$g_hBuffer] = _GDIPlus_ImageGetGraphicsContext($aTI[$g_hBitmap]) $aTI[$g_hPen] = _GDIPlus_PenCreate($iBarColor, 1) $aTI[$g_hIcon] = -1 $aTI[$g_sValues] = 0 $aTI[$g_iBackColor] = $iBackColor $aTI[$g_iMin] = $iMin $aTI[$g_iMax] = $iMax $aTI[$g_hShell32] = DllOpen('shell32.dll') _GDIPlus_GraphicsClear($aTI[$g_hBuffer], $iBackColor) _GDIPlus_GraphicsDrawImageRect($aTI[$g_hGraphics], $aTI[$g_hBitmap], 0, 0, 16, 16) _CreateTrayIcon() If @error Then Return SetError(@error, @extended, 0) Return 1 EndFunc ;==>_TIG_CreateTrayGraph ; #FUNCTION# ==================================================================================================================== ; Name...........: _TIG_SetBarColor ; Description ...: Sets Bar Color for tray icon ; Syntax.........: _TIG_SetBarColor($iBarColor = 0xFF00ACFF) ; Parameters ....: $iBarColor - Alpha, Red, Green and Blue Hex Value. (0xAARRGGBB). Default = Blue ; Return values .: Success - 1 ; Failure - 0 and sets @ERROR: ; - 1 ; Author ........: Beege ; Remarks .......: None ; =============================================================================================================================== Func _TIG_SetBarColor($iBarColor = 0xFF00ACFF) If $iBarColor = -1 Or $iBarColor = Default Then $iBarColor = 0xFF00ACFF _GDIPlus_PenSetColor($aTI[$g_hPen], $iBarColor) If @error Then Return SetError(1, @extended, 0) Return 1 EndFunc ;==>_TIG_SetBarColor ; #FUNCTION# ==================================================================================================================== ; Name...........: _TIG_SetBackGoundColor ; Description ...: Sets BackGround Color for tray icon ; Syntax.........: _TIG_SetBackGoundColor($iBackColor = 0xFF000000) ; Parameters ....: $iBarColor - Alpha, Red, Green and Blue Hex Value. (0xAARRGGBB). Default = Black ; Return values .: Success - 1 ; Author ........: Beege ; Remarks .......: None ; =============================================================================================================================== Func _TIG_SetBackGoundColor($iBackColor = 0xFF000000) If $iBackColor = -1 Or $iBackColor = Default Then $iBackColor = 0xFF000000 $aTI[$g_iBackColor] = $iBackColor Return 1 EndFunc ;==>_TIG_SetBackGoundColor ; #FUNCTION# ==================================================================================================================== ; Name...........: _TIG_UpdateTray ; Description ...: Update Tray Bar Graph with new Value ; Syntax.........: _TIG_UpdateTray($iValue) ; Parameters ....: $iValue - Value to update graph with ; Return values .: Success - 1 ; Failure - 0 and sets @ERROR: ; - Value returned from _WinAPI_GetLastERROR() ; Author ........: Beege ; Remarks .......: None ; =============================================================================================================================== Func _TIG_UpdateTrayGraph($iValue) $aTI[$g_sValues] = $iValue & '|' & $aTI[$g_sValues] Local $iX = 15, $split = StringSplit($aTI[$g_sValues], '|') _GDIPlus_GraphicsClear($aTI[$g_hBuffer], $aTI[$g_iBackColor]) For $y = 1 To $split[0] _GDIPlus_GraphicsDrawLine($aTI[$g_hBuffer], $iX, (16 - _CalcValue($split[$y])), $iX, 16, $aTI[$g_hPen]) $iX -= 1 Next _GDIPlus_GraphicsDrawImageRect($aTI[$g_hGraphics], $aTI[$g_hBitmap], 0, 0, 16, 16) If $split[0] = 16 Then $aTI[$g_sValues] = StringLeft($aTI[$g_sValues], StringInStr($aTI[$g_sValues], '|', 0, -1) - 1) _CreateTrayIcon() If @error Then Return SetError(@error, @extended, 0) Return 1 EndFunc ;==>_TIG_UpdateTrayGraph ; #FUNCTION# ==================================================================================================================== ; Name...........: _TIG_SetRange ; Description ...: Sets Minimum and Maximum Y values of the Graph ; Syntax.........: _TIG_SetRange($iMin = 0, $iMax = 100) ; Parameters ....: $iMin - Minimum Y Value. Must be Greater than 0. ; $iMax - Maximum Y Value ; Return values .: Success - 1 ; Failure - 0 and sets @ERROR: ; - 1 Minimum Value Less than zero ; Author ........: Beege ; Remarks .......: None ; =============================================================================================================================== Func _TIG_SetRange($iMin = 0, $iMax = 100) If $iMin < 0 Then Return SetError(1, @extended, 0) If $iMin = -1 Or $iMin = Default Then $iMin = 0 If $iMax = -1 Or $iMax = Default Then $iMax = 100 $aTI[$g_iMin] = $iMin $aTI[$g_iMax] = $iMax Return 1 EndFunc ;==>_TIG_SetRange #EndRegion Public Functions #Region Internel Functions ; #FUNCTION# ==================================================================================================================== ; Name...........: _TraySetIcon ; Author ........: Yashied ; Modified ......: Beege ; =============================================================================================================================== Func _TraySetIcon() Static $tNOTIFYICONDATA = DllStructCreate('dword Size;hwnd hWnd;uint ID;uint Flags;uint CallbackMessage;ptr hIcon;') Static $p_tNOTIFYICONDATA = DllStructGetPtr($tNOTIFYICONDATA) DllStructSetData($tNOTIFYICONDATA, 'Size', DllStructGetSize($tNOTIFYICONDATA)) DllStructSetData($tNOTIFYICONDATA, 'hWnd', $aTI[$g_hGUI]) DllStructSetData($tNOTIFYICONDATA, 'ID', 1) DllStructSetData($tNOTIFYICONDATA, 'Flags', 2) ; NIF_ICON DllStructSetData($tNOTIFYICONDATA, 'hIcon', $aTI[$g_hIcon]) Local $Ret = DllCall($aTI[$g_hShell32], 'int', 'Shell_NotifyIcon', 'dword', 1, 'ptr', $p_tNOTIFYICONDATA) If @error Or $Ret[0] = 0 Then Return SetError(_WinAPI_GetLastError(), 0, 0) Return 1 EndFunc ;==>_TraySetIcon Func _CreateTrayIcon() Local $hclone = _GDIPlus_BitmapCloneArea($aTI[$g_hBitmap], 0, 0, 16, 16) Local $hIcon = DllCall($__g_hGDIPDll, 'int', 'GdipCreateHICONFromBitmap', 'ptr', $hclone, 'int*', 0) If $aTI[$g_hIcon] <> -1 Then _WinAPI_DestroyIcon($aTI[$g_hIcon]) $aTI[$g_hIcon] = $hIcon[2] _GDIPlus_BitmapDispose($hclone) _TraySetIcon() If @error Then Return SetError(@error, @extended, 0) EndFunc ;==>_CreateTrayIcon Func _CalcValue($iValue) If $iValue >= $aTI[$g_iMax] Then Return 16 If $iValue <= $aTI[$g_iMin] Then Return 0 Local $fPercent = $iValue / $aTI[$g_iMax] Switch Int($fPercent * 100) Case 8 To 98 Return Int($fPercent * 16) Case 98 To 100 Return 16 Case 1 To 7 Return 1 EndSwitch EndFunc ;==>_CalcValue Func _GdiExit() If $aTI[$g_hIcon] <> -1 Then _WinAPI_DestroyIcon($aTI[$g_hIcon]) _GDIPlus_GraphicsDispose($aTI[$g_hGraphics]) _GDIPlus_GraphicsDispose($aTI[$g_hBuffer]) _GDIPlus_BitmapDispose($aTI[$g_hBitmap]) _GDIPlus_PenDispose($aTI[$g_hPen]) DllClose($aTI[$g_hShell32]) _GDIPlus_Shutdown() EndFunc ;==>_GdiExit #EndRegion Internel Functions TIG.au3 Edited December 15, 2018 by Beege careca and Colduction 1 1 Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
dantay9 Posted February 13, 2010 Share Posted February 13, 2010 That's cool. I have always loved animated tray icons. Link to comment Share on other sites More sharing options...
Beege Posted February 13, 2010 Author Share Posted February 13, 2010 That's cool. I have always loved animated tray icons.Thanks. I'm glad you like it. Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
UEZ Posted February 13, 2010 Share Posted February 13, 2010 Nice work. Here another example with your works expandcollapse popup#include "TIG.au3" Local $bColor, $fColor Local $TotalCpu, $nProcessCpu, $StartUser, $StartIdle, $StartKernel, $ProcStartKern, $ProcStartUser AdlibRegister("_ProcessCalc", 1000) GUISetState() HotKeySet('{ESC}', '_exit') _TIG_CreateTrayGraph(0, 100) $bColor = 0xFF000000 $fColor = 0xFF00A000 _TIG_SetBackGoundColor($bColor) _TIG_SetBarColor($fColor) While Sleep(100000000) WEnd Func _Exit() AdlibUnRegister("_ProcessCalc") Exit EndFunc ;==>_Exit Func _ProcessCalc() Local $tProcess, $tSystem, $tSystemt Local $IdleTime = DllStructCreate($tagFileTime), $KernelTime = DllStructCreate($tagFileTime), $UserTime = DllStructCreate($tagFileTime) Local $PCreationTime = DllStructCreate($tagFileTime), $PExitTime = DllStructCreate($tagFileTime), $hScriptHandle = _WinAPI_GetCurrentProcess() Local $PKernelTime = DllStructCreate($tagFileTime), $PUserTime = DllStructCreate($tagFileTime) DllCall('Kernel32.dll', "int", "GetSystemTimes", "ptr", DllStructGetPtr($IdleTime), "ptr", DllStructGetPtr($KernelTime), "ptr", DllStructGetPtr($UserTime)) DllCall('Kernel32.dll', "int", "GetProcessTimes", "hwnd", $hScripthandle, "ptr", DllStructGetPtr($PCreationTime), "ptr", DllStructGetPtr($PExitTime), "ptr", DllStructGetPtr($PKernelTime), "ptr", DllStructGetPtr($PUserTime)) $tProcess = (DllStructGetData($PKernelTime, 1) - $ProcStartKern) + (DllStructGetData($PUserTime, 1) - $ProcStartUser) $tSystem = (DllStructGetData($KernelTime, 1) - $StartKernel) + (DllStructGetData($UserTime, 1) - $StartUser) $tSystemt = (($tSystem - (DllStructGetData($IdleTime, 1) - $StartIdle)) * (100 / $tSystem)) $ProcStartKern = DllStructGetData($PKernelTime, 1) $ProcStartUser = DllStructGetData($PUserTime, 1) $StartIdle = DllStructGetData($IdleTime, 1) $StartKernel = DllStructGetData($KernelTime, 1) $StartUser = DllStructGetData($UserTime, 1) $ProcessCPU = ($tProcess / $tSystem) * 100 $TotalCPU = Round($tSystemt, 0) _TIG_UpdateTrayGraph($TotalCpu) ;~ ConsoleWrite('Total CPU Usage = ' & $TotalCpu & '%' & @CRLF) Return $TotalCpu EndFunc ;==>_ProcessCalc Just open Calc and do some calculation... UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Beege Posted February 14, 2010 Author Share Posted February 14, 2010 @UEZ Hey thanks for the example. I forgot about that one. I need to go back and change that to use the new static vars. Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
careca Posted December 15, 2018 Share Posted December 15, 2018 Hi, i get an issue on the line 236 pertaining undeclared var $ghGDIPDll, cant seem to make it work. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Beege Posted December 15, 2018 Author Share Posted December 15, 2018 39 minutes ago, careca said: Hi, i get an issue on the line 236 pertaining undeclared var $ghGDIPDll, cant seem to make it work. Change that to $__g_hGDIPDll careca 1 Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
careca Posted December 15, 2018 Share Posted December 15, 2018 Nice, works now, thanks. Where/how did you know what to change it to? Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
water Posted December 16, 2018 Share Posted December 16, 2018 That was one of the the tiny script breaking changes introduced with one of the latest new versions. careca 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now