Jump to content

TrayTip onClick Event?


 Share

Recommended Posts

Hello everyone! I'm new to the AutoIT Forum, but have been using AutoIT for a few years now.
I've finally gotten around to TrayTips, which I love the idea they're like Windows Notifications (at least on Win10) see attached photo, it didn't let me insert it as a link from Imgur for some reason...

But, I've been attempting to get the TrayTip to have an onClick action.
I've inserted a Global variable in front of it, and called it within the TrayGetMsg() switch and within the GUIGetMsg() switch, but still nothing happens.

I've managed to make sure the TrayMenu items (not in code snippet) work within the TrayGetMsg() Switch, which I thought that might help with making the TrayTip work. But, after hours of looking into forum posts, I haven't been able to find anything useful and some of the code doesn't work, or it's more complicated than it possibly should be.

traytip.png.ddfb296e3c2a91e696be446488464ac2.png

Here's a code snippet:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>
Opt("TrayMenuMode", 1)
Global $GUI = GUICreate("GUI TITLE", 431, 213, -1, -1)
Global $trayTip = TrayTip("AUTOIT Notification", "This is line 1" & @CRLF & "This is line 2", 10)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $trayTip
            MsgBox(0, "Notification Clicked!", " You've Clicked on the Notification!", 5)

    EndSwitch
    Switch TrayGetMsg()
        Case $trayTip
            MsgBox(0, "Notification Clicked!", " You've Clicked on the Notification!", 5)
    EndSwitch
WEnd

 

Is there something I'm missing? or is TrayTip's really not clickable / don't allow actions to be performed from a click?

Also, if this is in the wrong category, please move it to the correct one. I wasn't sure where I should post it.

Link to comment
Share on other sites

it shouldn't work like that

;~         Case $trayTip
;~             MsgBox(0, "Notification Clicked!", " You've Clicked on the Notification!", 5)
        Case Else
            ConsoleWrite("$nMsg=" & $nMsg & @CRLF)

it doesn't give me any value

 

As far for Switch TrayGetMsg() is for the tray icon, take a look

#include <StringConstants.au3>
#include <TrayConstants.au3>

Opt("TrayMenuMode", 3) ; These are options 1 and 2 for TrayMenuMode.

Local $bPaused = False
TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Blue.ico")

#Region === Tray_Menu ===
Local $idPaused = TrayCreateItem("Pause", -1, -1, $TRAY_ITEM_RADIO)
TrayItemSetState(-1, $TRAY_UNCHECKED)
TrayCreateItem("") ; Create a separator line.
Local $idExit = TrayCreateItem("Exit")
#EndRegion === Tray_Menu ===

ToolTip(@ScriptName & @CRLF & " ", @DesktopWidth / 2, @DesktopHeight / 5, "Started", 1)
Sleep(3000)
ToolTip("")

While 1
    _GetTrayMsg()
    Sleep(100)
WEnd

Exit

;----------------------------------------------------------------------------------------

Func GoToExit()    ; exit
    Exit
EndFunc   ;==>GoToExit
;----------------------------------------------------------------------------------------
Func _GetTrayMsg()
    While 1
        Switch TrayGetMsg()

            Case $TRAY_EVENT_PRIMARYDOUBLE ; Paused the loop.
                TogglePause()

            Case $idPaused ; Paused the loop.
                TogglePause()

            Case $idExit ; Exit the loop.
                GoToExit()

        EndSwitch

        If $bPaused = False Then ExitLoop

    WEnd
EndFunc   ;==>_GetTrayMsg
;----------------------------------------------------------------------------------------
Func TogglePause()

    If $bPaused = False Then
        $bPaused = True
        TrayItemSetState($idPaused, $TRAY_CHECKED)    ; $TRAY_UNCHECKED, $TRAY_CHECKED
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Red.ico")
    Else
        $bPaused = False
        TrayItemSetState($idPaused, $TRAY_UNCHECKED)    ; $TRAY_UNCHECKED, $TRAY_CHECKED
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Blue.ico")
    EndIf

;~  ConsoleWrite("$bPaused=" & $bPaused & @CRLF)

EndFunc   ;==>TogglePause

;----------------------------------------------------------------------------------------

 

I know that I know nothing

Link to comment
Share on other sites

I don't think that there's a way to interact with the tray tip, since looking at the helpfile it doesn't mention anything, and there's nothing returned when you call it: https://www.autoitscript.com/autoit3/docs/functions/TrayTip.htm
This means that setting Global $trayTip = TrayTip('') will do nothing, since nothing is returned from the function (aka like a control ID to do something with when it's clicked). 

I must have notifications/tray tips disabled somewhere since this doesn't do anything on my computer, so I can't test it further. 

 

Here's a thread with some related (not exact issue) information:

The main part of it that should be interesting is from Microsoft (https://learn.microsoft.com/en-us/windows/win32/shell/notification-area?redirectedfrom=MSDN ) : 

Quote

The notification area is not for critical information that must be acted on immediately. It is also not intended for quick program or command access. As of Windows 7, much of that functionality is best accomplished through an application's taskbar button.

 

Edited by mistersquirrle
Add additional info

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

@ioa747 I appreciate the response. It does return "1" as it's value. Which can be found with:

// It returns 1 with "If not @error"
Global $trayTip = TrayTip("AUTOIT Notification", "This is line 1" & @CRLF & "This is line 2", 10)
If not @error Then
    MsgBox(0, "", $trayTip)
EndIf

// using this I was able to replicate the MsgBox using:
// Also Returns True 
if $trayTip = true or 1 then
    MsgBox(0, "", "Notification Shown")
EndIf


@mistersquirrle, Yes, you're not wrong on this.
I can't seem to find the actual Function within AutoITs Program Directory, which maybe locating this can possibly help(?). When searching the directory, finding only: C:\Program Files (x86)\AutoIt3\Examples\Helpfile\TrayTip.au3 example and TrayConstants.au3 is the other only file found that is linked the TrayMenu. But it only contains Global Constants.

I'm thinking the only way to really get this "Click" is now through UDFs, which was something I was trying to avoid.

Link to comment
Share on other sites

22 minutes ago, GregoryAM said:

It does return "1" as it's value. Which can be found with:

;// It returns 1 with "If not @error"
Global $trayTip = "TrayTip"  ;TrayTip("AUTOIT Notification", "This is line 1" & @CRLF & "This is line 2", 10)
If not @error Then
    MsgBox(0, "", $trayTip)
EndIf

;// using this I was able to replicate the MsgBox using:
;// Also Returns True
if $trayTip = true or 1 then
    MsgBox(0, "", "Notification Shown")
EndIf

 

I know that I know nothing

Link to comment
Share on other sites

@ioa747, adding this into the GUI seems to be calling the Case $trayTip in both the TrayGetMsg() & GUIGetMsg() and showing the MsgBox that's inside of them.

I removed Func _TIP() since it's not doing anything, and replaced the msgbox with the traytip.
 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>
Opt("TrayMenuMode", 1)
Global $GUI = GUICreate("GUI TITLE", 431, 213, -1, -1)
Global $trayTip = 1
If $trayTip = 1 Then
    Global $trayTip = TrayTip("Notification", "Test Text", 10)
    $trayTip = 0
EndIf
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $trayTip = 0
            MsgBox(0, "Notification Clicked! - GUIGetMsg", " You've Clicked on the Notification!", 2)

    EndSwitch
WEnd

Doing this calls both the TrayTip and shows the MsgBox.

If you remove the 2 seconds from the Msgbox, it's not closable unless you force quit the script.

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

×
×
  • Create New...