Jump to content
Sign in to follow this  
jftuga

minimize another program to system tray

Recommended Posts

jftuga

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

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
jftuga
rdwray

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

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
rdwray

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

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
rdwray

M23, I am going to hibernate on this one, thanks...


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

Share this post


Link to post
Share on other sites
rdwray

M23, cannot this C++ file (attached) be implemented in au3?

RBTray.zip


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

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
rdwray

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

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.