Jump to content
Sign in to follow this  
RichardL

WAnt to Activate a Program Minimised to System Tray

Recommended Posts

RichardL

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

Share this post


Link to post
Share on other sites
Juvigy

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

Share this post


Link to post
Share on other sites
Ascend4nt

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

Share this post


Link to post
Share on other sites
RichardL

Thanks, it works. I've tried both versions on two different tray icons, I can't get to the real target program at the moment. Thanks again.

Share this post


Link to post
Share on other sites
RichardL

Thanks danwilli, what I find is WinSetState is good for normal windows, including minimised, but doesn't work if minimised to system tray with no item in task-bar (or alt-tab window).

Share this post


Link to post
Share on other sites
Ascend4nt

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]')

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.