Jump to content

Restore/maximize app in systray?


Go to solution Solved by littlebigman,

Recommended Posts

Posted (edited)

Hello,

I need to restore/maximize an app running in the systray, and click on one of its buttons.

The following does find the process, but the app isn't displayed:

If ProcessExists ( "blah.exe" ) then
    ConsoleWrite("Found" & @CRLF)
    ;NOTHING WinSetState("[TITLE:mytitle; CLASS:myclass]", "",@SW_RESTORE )
    ;NOTHING WinSetState("[CLASS:myclass]", "",@SW_RESTORE )
    ;NOTHING WinSetState("[CLASS:myclass]", "",@SW_MAXIMIZE )

    ;NOTHING WinActivate("[TITLE:mytitle; CLASS:myclass]", "")    
Else
    ConsoleWrite("Not found")
EndIf

Is this UDF still the recommended way to work with apps in the systray?

Thank you.

Edited by littlebigman
Posted

Here is my take:
WinExist to check whether the GUI actually exists:
- If it exists and WinActivate/WinSetState does nothing, then consider adding #RequireAdmin.
- If not, you might have to trigger the GUI creation by clicking the tray icon. maybe?

Posted

Thanks, I'll give it a try.

The UDF must have this line commented out:

#include <SysTray_UDF.au3> ;https://www.autoitscript.com/forum/topic/13704-systray_udf/
;error: $WM_GETTEXT previously declared as a 'Const'.
;Const $WM_GETTEXT = 13 ; Included in GUIConstants

Restoring/maximizing an app running in the systray seems a bit involved:

;Systray_test.au3
; -- Example 5 --
; Left-click Feedreader's icon on system tray
; Press hide inactive icon's button part is from Valik's refresh system tray script!
$oldMatchMode = Opt("WinTitleMatchMode", 4)
$oldChildMode = Opt("WinSearchChildren", 1)
$class = "classname=Shell_TrayWnd"
$hControl = ControlGetHandle($class, "", "Button2")
; get tray position and move there. Helps if Auto Hide tray option is used.
$posTray = WinGetPos(_FindTrayToolbarWindow ())
MouseMove($posTray[0], $posTray[1])
$index = _SysTrayIconIndex ("feedreader.exe"); Change this to some other application if needed
If $index <> -1 Then
   $pos = _SysTrayIconPos ($index)
   If $pos = -1 Then
      ; ***** Moved by CatchFish *****
      ; If XP and the Hide Inactive Icons mode is active
      If $hControl <> "" And ControlCommand($class, "", $hControl, "IsVisible", "") Then
         ControlClick($class, "", $hControl)
         Sleep(250); Small delay to allow the icons to be drawn
      EndIf
      ; ******************************
      $pos = _SysTrayIconPos ($index)
      If $pos = -1 Then Exit ; ** A real error this time;)
   EndIf
   MouseMove($pos[0], $pos[1])
   Sleep(1000)
   MouseClick("left")
EndIf
ConsoleWrite(@CRLF & @CRLF & "Pos[0]: " & $pos[0] & "$pos[1]: " & $pos[1])

; Restore Opt settings
Opt("WinTitleMatchMode", $oldMatchMode)
Opt("WinSearchChildren", $oldChildMode)

 

Posted

Getting closer: The mouse right-clicks the icon and the pop-up menu is displayed, but then It doesn't hit the down arrow + Enter to restore the window. Maybe focus must be put on the icon:

Const $MYAPP = "blah.exe"
Local $index = _SysTrayIconIndex ($MYAPP)
If $index <> -1 Then
   $pos = _SysTrayIconPos ($index)
   ;_ArrayDisplay($pos)
    MouseMove($pos[0], $pos[1])
    Sleep(1000)
    MouseClick("right")
    Sleep(1000)
;~     Send("{DOWN}") ;Doesn't click
;~     Sleep(1000)
;~     Send("{ENTER}")
EndIf

 

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