Jump to content

How to operate a icon in system tray?


Recommended Posts

The code above doesn't work when the wanted ToolTip has ButtonNumber = 0. The Get_Systray_Index function returns 0, so the "Icon not found in system tray" error message appears.

I have modified the code slightly:

#Include <GuiToolBar.au3>

Global $hSysTray_Handle, $iSystray_ButtonNumber

Global $sToolTipTitle = "" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = -1 Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
EndIf

Exit

;............

Func Get_Systray_Index($sToolTipTitle)

    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf

    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf

    ; Look for wanted tooltip
    $fToolTipFound = False
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
         $sButtonText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)
         If StringInStr($sButtonText, $sToolTipTitle) = 1 Then
            $fToolTipFound = True
            ExitLoop
         EndIf
    Next

    If $fToolTipFound = False Then
        Return -1 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...
On 28/12/2016 at 6:32 PM, war59312 said:

Not working on Windows 10 x64 it seems.

Googling a bit.. Says replace "Instance:1" with "instance:2", but then I get "No items found in system tray" error.

There are two ToolbarWindow32 sub-classes in the Shell_TrayWnd class. We need the "User Promoted Notification Area" one. So use the following code 

$hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "User Promoted Notification Area")

Compile X64 version and use it in Windows 10 (works in Window 7 as well).

ToolbarWindow32png.png

Link to comment
Share on other sites

  • 7 years later...

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