Jump to content

[Solved] How To Refresh Traytooltip Display ?


Exit
 Share

Go to solution Solved by KaFu,

Recommended Posts

Edit: @KaFu solved it. Thanks.     ############################################################

Here is Kafu's code. See 14 posts below.

Func _TraySetToolTip_Ex($sText = "")
    ; #include "_TraySetToolTip_Ex.au3" ; http://www.autoitscript.com/forum/index.php?showtopic=146910
    If Not $sText Then $sText = Chr(0) ; Chr(0) = no tooltip displayed
    TraySetToolTip($sText)
    Local $_SysTray_hToolTip = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", ControlGetHandle(ControlGetHandle(ControlGetHandle(WinGetHandle("[CLASS:Shell_TrayWnd]"), "", "[CLASS:TrayNotifyWnd]"), "", "[CLASS:SysPager]"), "", "[CLASS:ToolbarWindow32; INSTANCE:1]"), "uint", 0x423, "wparam", 0, "lparam", 0) ; $TB_GETTOOLTIPS = 0x423
    $_SysTray_hToolTip = HWnd($_SysTray_hToolTip[0])
    If Not IsHWnd($_SysTray_hToolTip) Or WinGetTitle($_SysTray_hToolTip) <> $sText Then Return
    DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $_SysTray_hToolTip, "uint", 0x41D, "wparam", 0, "lparam", 0) ; $TTM_UPDATE = 0x41D
EndFunc   ;==>_TraySetToolTip_Ex

End of Edit    ###########################################################################

 

;
; When I hoover over the tray icon, the current time is displayed, but not updated until I move the mouse away and back.
; Is there a magic command to refresh the traytooltip display during hoovering ?
;
HotKeySet("{ESC}", "_ESC")
Func _ESC()
Exit
EndFunc ;==>_ESC
;
While Sleep(1000)
TraySetToolTip(@HOUR& ":" & @MIN & ":"& @SEC)
; insert the magic command here.
WEnd

 

Edited by Exit
Set topic solved

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

I use code like this in a 'clock' script. This would probably work for you, of course you would have to incorporate the @SEC macro, and you would replace the line where I use the GUICtrlSetData function with the TraySetToolTip function.

Local $CurrentTime = @HOUR & @MIN

While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    If $CurrentTime <> @HOUR & @MIN Then
        $CurrentTime = @HOUR & @MIN
        GUICtrlSetData($ClockLabel, TheTime())
    EndIf
    Sleep(100)
WEnd

See how it works? The display only gets updated when needed.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Thanks, but this does not help.. I want to update the display of a traytooltip when hoovering over the trayicon.

The clockdisplay is only a sample to change the traytooltip every second.

But the display of the traytooltip alters only if you move the mouse away from the trayicon and then back again.

I am looking for a method to update the display of the traytooltip every second, even if the mouse remains on the trayicon.

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

  • 8 months later...
  • 1 year later...

a slightly diff approach:

HotKeySet("{ESC}", "_ESC")
Func _ESC()
Exit
EndFunc ;==>_ESC
;
While Sleep(1000)
TrayTip ( "", @HOUR& ":" & @MIN & ":"& @SEC,500 )
TraySetToolTip(@HOUR& ":" & @MIN & ":"& @SEC)
; insert the magic command here.
WEnd
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

It's not what I'm searching for... I need to change the text of the tray icon box that appear while mouseover that, and to be able to update and show the refreshed text during mouseover!

Link to comment
Share on other sites

Maybe I can try to operate on the icon through IUserNotification::SetIconInfo method...

But how do I retrieve the handle of the standard Autoit icon? I don't think the handle returned by

TrayItemGetHandle(0)

is the right one :(

Link to comment
Share on other sites

; Johnmcloud - 2015
#include <Constants.au3>

HotKeySet("{ESC}", "_Exit")

TraySetToolTip("")

While 1
    Switch TrayGetMsg()
        Case $TRAY_EVENT_MOUSEOVER
            TrayTip("", @HOUR & ":" & @MIN & ":" & @SEC, 1)
        Case Else
            TrayTip("", "", 5)
    EndSwitch
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Edited by johnmcloud
Link to comment
Share on other sites

I don't want the balloon notify, I need the square notify... And if you try to change your script in:

Case $TRAY_EVENT_MOUSEOVER
    TraySetToolTip(@HOUR & ":" & @MIN & ":" & @SEC)

It is not updated while mouseover it

Edited by j0kky
Link to comment
Share on other sites

Try this:

#include <Constants.au3>

HotKeySet("{ESC}", "_Exit")

Global $aMPosOld[2], $fHover = False, $fTooltip = False

_TraySetNoToolTip()

While 1
    $aMPosCurr = MouseGetPos()
    If $aMPosCurr[0] <> $aMPosOld[0] Or $aMPosCurr[1] <> $aMPosOld[1] Then
        $iMsg = TrayGetMsg()
        Switch $iMsg
            Case $TRAY_EVENT_MOUSEOVER
                $fHover = True
            Case Else
                $fHover = False
        EndSwitch
        $aMPosOld[0] = $aMPosCurr[0]
        $aMPosOld[1] = $aMPosCurr[1]
    EndIf
    If $fHover And Not $fTooltip Then
        $fTooltip = True
        AdlibRegister('_ToolTipEnable', 100)
    EndIf
    Sleep(10)
WEnd

Func _ToolTipEnable()
    Local Static $aMousePos = MouseGetPos()
    If $fHover Then ToolTip(@HOUR & ":" & @MIN & ":" & @SEC, $aMousePos[0], $aMousePos[1] - 30)
    If Not $fHover Then ToolTip("")
EndFunc   ;==>_ToolTipEnable

Func _TraySetNoToolTip()
    Return TraySetToolTip(Chr(0))
EndFunc

Func _Exit()
    Exit
EndFunc   ;==>_Exit

In theory need to "disable" the default tooltip of the tray but require some knowledge i don't have, like DllStructSetData + Shell_NotifyIconW

Was so easy to remove the default tooltip, i have update the script.

An alternative without AdlibRegister and Static Y

#include <Constants.au3>

HotKeySet("{ESC}", "_Exit")

Global $aMPosOld[2], $fHover = False, $fTooltip = False

_TraySetNoToolTip()

While 1
    $aMPosCurr = MouseGetPos()
    If $aMPosCurr[0] <> $aMPosOld[0] Or $aMPosCurr[1] <> $aMPosOld[1] Then
        $iMsg = TrayGetMsg()
        Switch $iMsg
            Case $TRAY_EVENT_MOUSEOVER
                $fHover = True
            Case Else
                $fHover = False
        EndSwitch
        $aMPosOld[0] = $aMPosCurr[0]
        $aMPosOld[1] = $aMPosCurr[1]
    EndIf
    If $fHover Then
        $fTooltip = True
        _SetToolTip()
    ElseIf Not $fHover And $fTooltip Then
        $fTooltip = False
        ToolTip("")
    EndIf
    Sleep(10)
WEnd

Func _SetToolTip()
    Local Static $aXMousePos = MouseGetPos(0)
    Local $aYMousePos = MouseGetPos(1)
    ToolTip(@HOUR & ":" & @MIN & ":" & @SEC, $aXMousePos, $aYMousePos - 30)
EndFunc

Func _TraySetNoToolTip()
    Return TraySetToolTip(Chr(0))
EndFunc

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Edited by johnmcloud
Link to comment
Share on other sites

Here you go..._GUIToolTip_Update

#include <GuiToolTip.au3>
$sPrevious = @HOUR& ":" & @MIN & ":"& @SEC
TraySetToolTip($sPrevious)
While True
    $a = WinList("[CLASS:tooltips_class32]")
    For $i = 1 To UBound($a)-1
        If WinGetTitle($a[$i][1]) = $sPrevious Then
            $sNew = @HOUR& ":" & @MIN & ":"& @SEC
            If $sNew <> $sPrevious Then
                ConsoleWrite(WinGetTitle($a[$i][1]) & @CRLF)
                TraySetToolTip($sNew)
                WinSetTitle($a[$i][1],"",$sNew)
                ControlSetText($a[$i][1],"","",$sNew)
                _GUIToolTip_Update($a[$i][1])
                $sPrevious = $sNew
            EndIf
        EndIf
    Next
    Sleep(10)
WEnd
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

@JohmCloud: Your solution is really ingenious!

But it has two problems:

- As you've told, we need to disable the default icon description in some way:

2pq7uh2.jpg

- When, by default, the icon is moved to notification area overflow, here it is what happens to your tooltip (I don't know why):

2e199np.jpg

In my opinion the only way to solve this problem is to proceed as Windows wants: through MSDN APICOM.

But to do that I need to know the handle of the default Autoit taskbar icon... I think I'll open a separate thread to talk about this.

@Jdelaney: you're a genius! It works really well :D I didn't know the existence of that UDF  :oops:

EDIT2:

Excuse me, Jdelaney, but where do you documented about tooltips_class32 ?

In MSDN library there is just a little hint about it in Automation Appendix  :o  :o  :o

Edited by j0kky
Link to comment
Share on other sites

v2

#include <GuiToolbar.au3>
#include <WinApi.au3>
 
HotKeySet("{ESC}", "_Exit")
 
Global $_SysTray_hTrayWnd = WinGetHandle("[CLASS:Shell_TrayWnd]")
Global $_SysTray_hTrayNotifyWnd = ControlGetHandle($_SysTray_hTrayWnd, "", "[CLASS:TrayNotifyWnd]")
Global $_SysTray_hSysPager = ControlGetHandle($_SysTray_hTrayNotifyWnd, "", "[CLASS:SysPager]")
Global $_SysTray_hToolbar = ControlGetHandle($_SysTray_hSysPager, "", "[CLASS:ToolbarWindow32; INSTANCE:1]") ; User Promoted Notification Area/Notification Area/SysTray
Global $_SysTray_hToolTip = _GUICtrlToolbar_GetToolTips($_SysTray_hToolbar)
 
TraySetToolTip("Test " & TimerInit() & 11111111111111111111)
AdlibRegister("_Update_Tooltip", 100)
 
While 1
Sleep(10)
WEnd
 
Func _Update_Tooltip()
If BitAND(WinGetState($_SysTray_hToolTip), 2) Then ; if tooltip is visible
 
; To test variable string length
Local $s_String = "Test " & TimerInit() & " "
For $i = 0 To Random(10, 99)
$s_String &= 1
Next
TraySetToolTip($s_String)
 
; Updates displayed string, but does not resize tooltip if string is too small or large...
; Tooltip remains of the size necessary to display the initial string
_WinAPI_RedrawWindow($_SysTray_hToolTip)
 
EndIf
EndFunc   ;==>_Update_Tooltip
 
Func _Exit()
Exit
EndFunc   ;==>_Exit
Edited by KaFu
Link to comment
Share on other sites

  • Solution

Slightly optimized v3 taking jdelaneys code into account  :lol: ...

Func _TraySetToolTip_Ex($sText)
If Not $sText Then $sText = Chr(0) ; Chr(0) = no tooltip displayed
TraySetToolTip($sText)
Local $_SysTray_hToolTip = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", ControlGetHandle(ControlGetHandle(ControlGetHandle(WinGetHandle("[CLASS:Shell_TrayWnd]"), "", "[CLASS:TrayNotifyWnd]"), "", "[CLASS:SysPager]"), "", "[CLASS:ToolbarWindow32; INSTANCE:1]"), "uint", 0x423, "wparam", 0, "lparam", 0) ; $TB_GETTOOLTIPS = 0x423
$_SysTray_hToolTip = HWnd($_SysTray_hToolTip[0])
if not IsHWnd($_SysTray_hToolTip) or WinGetTitle($_SysTray_hToolTip) <> $sText Then Return
DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $_SysTray_hToolTip, "uint", 0x41D, "wparam", 0, "lparam", 0) ; $TTM_UPDATE = 0x41D
EndFunc   ;==>_TraySetToolTip_Ex
Link to comment
Share on other sites

This is my version with Jdelaney & KaFu experiences joined:

Func _TraySetToolTip_Ex($sText)
    If $sText == "" Then $sText = Null ;Null = "" and Not (Null == ""), this is useful for WinGetTitle
    TraySetToolTip($sText)
    Local $tt_array = WinList("[CLASS:tooltips_class32]")
    For $i = 1 To $tt_array[0][0]
        If WinGetTitle($tt_array[$i][1]) == $sText Then DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $tt_array[$i][1], "uint", 0x41D, "wparam", 0, "lparam", 0)
    Next
EndFunc

But I'm not completely satisfied... We're working only with tooltips... What about Tray icon handle?

Link to comment
Share on other sites

What about try icon handle? It seems as there is only one tooltip in the tray, which is re-used for the icon you're hovering over. If you want to obtain icon handles, take a look at HMW in my signature. I tested to manipulate the text in the tray icon structure itself, but that did not update the tooltip, in fact it only seemed like the hard way for TraySetToolTip() :).

Link to comment
Share on other sites

I think SysTrayGetButtonInfo function from _SysTray can be the solution...

But I really don't understand why it is necessary to play with shared memory of explorer.exe to retrieve the icon handle, while my Autoit executable conceals in its code the icon handle (since the interpreter added that code before building it).

Why Autoit devs don't make that handle accessible via a Macro?!  :wacko:

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...