Jump to content

Opening the context menu by right click on the tray icon


Recommended Posts

Hi All,

I am new to AutoIt, and I am facing a problem with repect to right click on the tray icon. It will be great if some one can guide me on how to solve the same.

Problem statement:

I have an application,on invoking the application a tray Icon for the same is created. Right Clicking on the tray Icon actually, gives me an option called Login. clicking on that will show me teh Login screen. ( we can consider it as similiar to what we have with skype, When skype is running it creates a tray icon and Right Click on the tray icon gives an option as 'Open Skype')

Now the problem is I am not able to Right Click on the icon to invoke my menu Options.

Any help on this is highly appreciated.

Thanks

Link to comment
Share on other sites

Check out this example. It is for the outlook tray icon.

#Include <GuiToolBar.au3>
#NoTrayIcon

Global $hSysTray_Handle, $iSystray_ButtonNumber

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

;~ WinActivate('[Class:Shell_TrayWnd]') ; if taskbar is Autohide

$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
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then 
            MsgBox(0,$iSystray_ButCount,$iSystray_ButtonNumber)
            Return $iSystray_ButtonNumber ; Found
        EndIf
    Next
    Return -1 ; Not found

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