Jump to content

minimize another program to system tray


Recommended Posts

I searched the forums but didn't seem to find exactly what I was looking for. Is it possible to write an AutoIt script to make a 3rd-party application (no source, .exe only) minimuze to the system tray (next to the clock) instead of the taskbar?

Thanks,

-John

Edited by jftuga
Link to comment
Share on other sites

  • Moderators

jftuga,

Yes. :)

And you can do it like this:

Run("Calc.exe")
WinWait("Calculator")

TraySetIcon("Calc.exe")

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

$hTray_Show_Item = TrayCreateItem("Hide")
TrayItemSetOnEvent(-1, "To_Tray")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")


While 1
    Sleep(10)
WEnd

Func On_Exit()
    WinKill("Calculator")
    Exit
EndFunc

Func To_Tray()

    If TrayItemGetText($hTray_Show_Item) = "Hide" Then
        WinSetState("Calculator", "", @SW_HIDE)
        TrayItemSetText($hTray_Show_Item, "Show")
    Else
        WinSetState("Calculator", "", @SW_SHOW)
        TrayItemSetText($hTray_Show_Item, "Hide")
    EndIf

EndFunc

I hope that is what you wanted. :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 1 year later...

M23, I know this is not a new post, but I would like to get some expanded information. I am running a program called "TrayIt" which I am sure some are familiar with. The unique ability over the example script is that TrayIt is not dedicated to just one application, but allows the addition of others and runs in the background and invisible to the user - simply hit the applications minimize button and it goes to the tray.

I would like to be able to add the close button and send the app to the tray like one add-on does for Thunderbird by target program for now.

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
Share on other sites

  • Moderators

rdwray,

Looking for an app to be minimized and then sending it to the tray is not too difficult - especially if you only use a single icon with a context menu as I showed above. Intercepting the closure [X] is another matter - I do not think you can do that to a third party app. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

rdwray,

Looking for an app to be minimized and then sending it to the tray is not too difficult - especially if you only use a single icon with a context menu as I showed above. Intercepting the closure [X] is another matter - I do not think you can do that to a third party app. :oops:

M23

M23, I took the routine above and tried to add "GUISetOnEvent($GUI_EVENT_MINIMIZE, "To_Tray")" so that "Calculator"s minimize would be intercepted and it never worked - Calc stayed normal, and even with a MsgBox as a check was never activated. I also noticed that there is a $GUI_EVENT_CLOSE; see "added" in code.

Help file says: Defines a user function to be called when a system button is clicked."

#include <GUIConstantsEx.au3> ; added

Run("Calc.exe")
WinWait("Calculator")

TraySetIcon("Calc.exe")

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.
Opt("GUIOnEventMode", 1)  ; added

$hTray_Show_Item = TrayCreateItem("Hide")
TrayItemSetOnEvent(-1, "To_Tray")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

GUISetOnEvent($GUI_EVENT_MINIMIZE, "To_Tray")  ; added

While 1
    Sleep(10)
WEnd

Func On_Exit()
    WinKill("Calculator")
    Exit
EndFunc

Func To_Tray()

MsgBox(0,0,0)  ; added
    If TrayItemGetText($hTray_Show_Item) = "Hide" Then
        WinSetState("Calculator", "", @SW_HIDE)
        TrayItemSetText($hTray_Show_Item, "Show")
    Else
        WinSetState("Calculator", "", @SW_SHOW)
        TrayItemSetText($hTray_Show_Item, "Hide")
    EndIf

EndFunc

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Link to comment
Share on other sites

  • Moderators

rdwray,

The events mentioned in the Help file are the ones sent by a GUI you have created in your own script - we are talking here of third party apps. :bye:

Intercepting their messages is much more difficult and I believe you need an external DLL to do it - here is something I coded a while back to show how you can indeed intercept some messages from third party apps with a DLL. However, I have real reservations about whether you can intercept a closure [X] at all. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

rdwray,

Quite possibly - I linked to a script which used an external DLL and I dare say this uses similar calls. But I have my doubts that you can do it from within an AutoIt script given the interprocess boundaries that Windows uses. :oops:

Anyway, I am not volunteering to do it - why do you not give it a try yourself? :bye:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

rdwray,

Quite possibly - I linked to a script which used an external DLL and I dare say this uses similar calls. But I have my doubts that you can do it from within an AutoIt script given the interprocess boundaries that Windows uses. :oops:

Anyway, I am not volunteering to do it - why do you not give it a try yourself? :bye:

M23

Interprocess - sounds like it may be a wall. I am looking at some scripts that use the non-client area and I may get a headache before this one is over - to dump to stop.

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

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