benbuck / rbtray

A fork of RBTray from http://sourceforge.net/p/rbtray/code/.
GNU General Public License v2.0
1.07k stars 88 forks source link

Command-Line option: Start new program minimized #20

Open patricknelson opened 5 years ago

patricknelson commented 5 years ago

NOTE: I've copied/modified this request from the Sourceforge feature request here: https://sourceforge.net/p/rbtray/feature-requests/11/


It would be nice, if one could also use RBTray to start a new program minimized.

For example:

"C:\RBTray.exe Notepad.exe"

Would start Notepad.exe minimized in the system tray. I would use this, to start some programs service-like but still accessible in the system tray.

benbuck commented 5 years ago

Hi @patricknelson,

I can see how this would be useful, but so far I haven't been able to think of a good way to implement it due to limitations in the APIs that Windows provides.

-Benbuck

benbuck commented 5 years ago

Hi @patricknelson,

I was just researching this a little, and found that there is at least one utility that can do it called Actual Window Minimizer (https://www.actualtools.com/windowminimizer/). So for sure it's possible, but seeing how they did it, the UI and settings required may be more than I care to add to RBTray, but I'll think about it.

Also, it looks like you may be able to cobble something together with AutoHotKey if you care to invest the time and effort: https://www.autohotkey.com/boards/viewtopic.php?t=4373.

-Benbuck

pstein commented 4 years ago

Just want to say that I would appreciate this feature too

parkstraat9 commented 3 years ago

This would be a great feature.

tuaone commented 2 years ago

Just want to say that I would appreciate this feature too

james28909 commented 2 years ago

i think the reason it cannot be implemented easily is because you have to fake clicks which requires you to get the client screen size, then get the window size... and then calculate where the minimize button is mathematically, and then fake a right click event. ive done this and scheduled a task for when the executable is run, it will automatically run my script which does the calculation and fake mouse right click.

if anyone is interested in the script just let me know. im sure i could add a arg to be able to input the window to be systrayed. if anyone is interested let me know

garoto commented 2 years ago

i think the reason it cannot be implemented easily is because you have to fake clicks [...]

Programming APIs don't need to fake mouse clicks. You invoke a function exposed by a OS provided library which is responsible for GUI manipulation and whatnot.

james28909 commented 2 years ago

Programming APIs don't need to fake mouse clicks. You invoke a function exposed by a OS provided library which is responsible for GUI manipulation and whatnot.

what function is exposed when you right click the minimize button? is there an open source lib that already has this implemented that someone can study?

garoto commented 2 years ago

Plenty of open-source Windows programs offer the option of being started minimized in the systray. From the top of my head: ditto-cp, hexchat, AltSnap.

Either browse their code or ask the authors directly.

james28909 commented 2 years ago

ive acheived this task with AutoHotKey script Min2Tray which was released here on the autohotkey forums.

in order to add windows to the "StartUpMinimized" list, you have to minimize them to tray via min2tray script or compiled executable, then right click the minimized windows tray icon and go to "preferences" and select "Windows is on the StartUpMinimized list. i also selected "Minimize window immediately (skip the task bar)" as well. also, im on the latest win 11 and it seems to be functioning flawlessly for me. have enabled the option to minimize to tray when right clicking the close button too.

works very good for such an old piece of software

Mansarde commented 1 year ago

Why is it closed?

What do you mean? This issue is open.

patricknelson commented 1 year ago

I see the confusion. Looks like #68 was closed, not this one 😄

JamesHoi commented 8 months ago

It seems min2tray that james28909 mention not work for me. I have done a simple script for this issue. However, I dont think this is a elegant implementation because you can see the program start minimize in taskbar and minimize to tray quickly. https://gist.github.com/JamesHoi/3d884caaeaa3626ae0ee3d8367c8ae75

By the way, I use SW_MINIMIZE for starting new program without display so the function in RestoreWindowFromTray should be changed to SW_SHOWNORMAL. I have also tried using the flag SW_HIDE, but somehow it cannot be restored window by rbtray. https://github.com/benbuck/rbtray/blob/2de7ba80967ab36039c6a95b46c0ca3a265d6d82/RBTray.cpp#L147