Jump to content

Recommended Posts

Posted

Hi,

I've been trying to write a script to interact with Windows System Tray Application like Microsoft Outlook. I've searched the forums and followed many of the examples, but somehow when the script is run, it doesn't click the appropriate tray icon. Here is a link to one such example - https://www.autoitscript.com/forum/topic/133222-manipulate-system-tray-program-right-click-choose-option/

I followed the example, and instead of clicking the Microsoft Outlook tray icon, it clicks the Windows Taskbar and opens up the menu for taskbar.

Here is the code for quick reference:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_x64=tray.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <GuiToolBar.au3>
#include <GuiButton.au3>

Global $hSysTray_Handle, $iSystray_ButtonNumber

Global $sToolTipTitle = "Microsoft Outlook" ; <<<<<<<<<<<<<<<< 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)
    ; right click and select first menu item
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
    Send("{DOWN}{ENTER}")
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
        ; check overflow section of systray
         Return Get_OverflowSystray_Index($sToolTipTitle)
    EndIf

    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return Get_OverflowSystray_Index($sToolTipTitle)
     Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc


Func Get_OverflowSystray_Index($sToolTipTitle)

   $hSysTray_Handle = ControlGetHandle('[Class:NotifyIconOverflowWindow]', '', '[Class:ToolbarWindow32;Instance:1]')
   $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
   If $iSystray_ButCount = 0 Then
      MsgBox(16, "Error", "No items found in system tray")
      Exit
   EndIf

   For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
     If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
   Next
   If $iSystray_ButtonNumber < $iSystray_ButCount Then
      $hSysTray_OverflowButton = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[CLASS:Button; INSTANCE:1]')
      _GUICtrlButton_Click($hSysTray_OverflowButton)
      Return $iSystray_ButtonNumber ; Found
   Else
      Return -1
   EndIf

EndFunc

Any help is really appreciated.

Thank you.

Posted

in line 30 change  from:
$hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
to
$hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:3]')

and make sure the Outlook icon is visible and not hidden

 

I know that I know nothing

Posted

Thank you.

Made the change but it didn't make any difference.

What does it mean 'Outlook icon is visible'? When I click the 'NotifyIconOverflowWindow' it does show the icon if that' what it means to be visible.

 

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
  • Recently Browsing   0 members

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