Jump to content

WAnt to Activate a Program Minimised to System Tray


Recommended Posts

Hello. I have a program that is minimised to system tray, and I want to activate it to normal window (and then click on buttons etc.) Yes I could probably find it by looking for its icon’s colours, not very clever. I know the program name, can I find the icon and send it a ‘double-click’ message? (I’ve tried WinActivate – no action.)

Link to comment
Share on other sites

This example is about outlook:

Include <GuiToolBar.au3>
#NoTrayIcon

Global $hSysTray_Handle, $iSystray_ButtonNumber

Global $sToolTipTitle = "Microsoft Office 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)
    _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

Juvigy, Since the instance # for the 'Notification Area' can vary between O/S's, you might want to alter the following line:

$hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')

to search for '[CLASS:ToolbarWindow32;TEXT:Notification Area]' on anything pre-Windows 7, and for Windows 7:

"[CLASS:ToolbarWindow32;TEXT:User Promoted Notification Area]".

Link to comment
Share on other sites

I just gave Juvigy's code above a try myself.. I didn't realize that if you have an 'Auto-Hide' taskbar, you'll need to Activate it, like this first (right before _GUICtrlToolbar_ClickButton):

WinActivate('[Class:Shell_TrayWnd]')
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...