Jump to content

Can I display progress info on the icon in the tray?


Recommended Posts

Quite often I'm using AutoIt to drive a program which is maximised and has the focus.  I want to display progress info but where?  If I put up a normal window it takes the focus and destroys the action.  I've tried a GDI+ window (built from one of UEZ examples) but it hides some of the target program.  Can I:

- change the AutoIt icon in the system tray with dynamic info?  e.g. like Task Manager shows a bargraph? 

- make the icon flash, and the task bar un-hide (if it's set to auto-hide)?

- pop up a tooltip or balloon, and then take it away?

Any other ideas?

Thanks.

Link to comment
Share on other sites

Here an idea using one of the examples from here:

_GDIPlus_SpinningAndGlowing:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

AutoItSetOption("TrayMenuMode", 3)

Global Const $tagNOTIFYICONDATA = "dword Size;" & _
        "hwnd Wnd;" & _
        "uint ID;" & _
        "uint Flags;" & _
        "uint CallbackMessage;" & _
        "ptr Icon;" & _
        "wchar Tip[128];" & _
        "dword State;" & _
        "dword StateMask;" & _
        "wchar Info[256];" & _
        "uint Timeout;" & _
        "wchar InfoTitle[64];" & _
        "dword InfoFlags;" & _
        "dword Data1;word Data2;word Data3;byte Data4[8];" & _
        "ptr BalloonIcon"

Global Const $NIM_ADD = 0, $NIM_MODIFY = 1, $NIF_MESSAGE = 1, $NIF_ICON = 2, $AUT_WM_NOTIFYICON = $WM_USER + 1, $AUT_NOTIFY_ICON_ID = 1, $TRAY_ICON_GUI = WinGetHandle(AutoItWinGetTitle())

_GDIPlus_Startup()
Global $hGui = GUICreate("Tray Anim", 0, 0)
GUISetState(@SW_HIDE)
Global $idExit = TrayCreateItem("Exit")
Global $hBmp_Anim, $hIcon, $iPerc = 0, $iSleep = 20, $fPower = 2

GUIRegisterMsg($WM_TIMER, "PlayAnim")
DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGui, "int", 0, "int", $iSleep, "int", 0)

TrayTip("Information", "Please wait while doing something...", 10)

Do
   Switch TrayGetMsg()
        Case $idExit
            GUIRegisterMsg($WM_TIMER, "")
            _GDIPlus_ImageDispose($hBmp_Anim)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
Until False

Func PlayAnim()
    $hBmp_Anim = _GDIPlus_SpinningAndGlowing($iPerc)
    $hIcon = _GDIPlus_HICONCreateFromBitmap($hBmp_Anim)
    _Tray_SetHIcon($hIcon)
    _GDIPlus_ImageDispose($hBmp_Anim)
    _WinAPI_DestroyIcon($hIcon)
    $iPerc += $fPower
EndFunc   ;==>PlayAnim


Func _GDIPlus_SpinningAndGlowing($fProgress, $iW = 16, $iH = 16, $iColor = 0xFF6644FF, $fSize = 7, $iCnt = 12, $fDM = 9, $fScale = 2.1, $iGlowCnt = 1.1, $iClearBg = 0xFF000000)
    Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx, 2)
    _GDIPlus_GraphicsClear($hGfx, $iClearBg)

    Local $iOff = $iCnt * Mod($fProgress, 100) / 100
    Local $fCX = $iW * 0.5
    Local $fCY = $iH * 0.5

    Local $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddEllipse($hPath, -$fDM * 0.5, -$fDM * 0.5, $fDM, $fDM)
    Local $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath)
    _GDIPlus_PathBrushSetCenterColor($hBrush, $iColor)
    _GDIPlus_PathBrushSetSurroundColor($hBrush, 0)
    _GDIPlus_PathBrushSetGammaCorrection($hBrush, True)

    Local $aBlend[5][2] = [[4]]
    $aBlend[1][0] = 0
    $aBlend[1][1] = 0
    $aBlend[2][0] = BitOR(BitAND($iColor, 0x00FFFFFF), 0x1A000000)
    $aBlend[2][1] = 0.78
    $aBlend[3][0] = BitOR(BitAND($iColor, 0x00FFFFFF), 0xFF000000)
    $aBlend[3][1] = 0.88
    $aBlend[4][0] = 0xFFFFFFFF
    $aBlend[4][1] = 1
    _GDIPlus_PathBrushSetPresetBlend($hBrush, $aBlend)

    Local $fS
    Local Const $cPI = ATan(1) * 4
    For $i = 0 To $iCnt - 1
        $fS = Sin($cPI * Log(1.4 + Mod($iOff + $i, $iCnt) / $iGlowCnt) / Log(4))
        If $fS < 0 Then $fS = 0
        $fS = 1 + $fScale * $fS

        _GDIPlus_GraphicsResetTransform($hGfx)
        _GDIPlus_GraphicsScaleTransform($hGfx, $fS, $fS, True)
        _GDIPlus_GraphicsTranslateTransform($hGfx, -$fSize, 0, True)
        _GDIPlus_GraphicsScaleTransform($hGfx, 1.2, 1, False)
        _GDIPlus_GraphicsRotateTransform($hGfx, -360 / $iCnt * $i, True)
        _GDIPlus_GraphicsTranslateTransform($hGfx, $fCX, $fCY, True)

        _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hBrush)
    Next

    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PathDispose($hPath)

    _GDIPlus_GraphicsDispose($hGfx)
    Return $hBmp
EndFunc   ;==>_GDIPlus_SpinningAndGlowing

Func _Tray_SetHIcon($hIcon) ;by Mat
    Local $tNOTIFY = DllStructCreate($tagNOTIFYICONDATA)
    DllStructSetData($tNOTIFY, "Size", DllStructGetSize($tNOTIFY))
    DllStructSetData($tNOTIFY, "Wnd", $TRAY_ICON_GUI)
    DllStructSetData($tNOTIFY, "ID", $AUT_NOTIFY_ICON_ID)
    DllStructSetData($tNOTIFY, "Icon", $hIcon)
    DllStructSetData($tNOTIFY, "Flags", BitOR($NIF_ICON, $NIF_MESSAGE))
    DllStructSetData($tNOTIFY, "CallbackMessage", $AUT_WM_NOTIFYICON)

    Local $aRet = DllCall("shell32.dll", "int", "Shell_NotifyIconW", "dword", $NIM_MODIFY, "struct*", $tNOTIFY)
    If @error Then Return SetError(1, 0, 0)

    Return 1
EndFunc   ;==>_Tray_SetHIcon

to animate the tray icon.

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...