Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

HideToTray with icons


  • Please log in to reply
10 replies to this topic
skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
8) HideToTray will hide the active window to the tray.

Start HideToTray, doubleclick it's tray icon to hide the active window to the tray, showing the program's icon. Doubleclick the new icon to unhide it again, rightclick to show a menu. The procedure can be done again to hide more windows.

It consists of two scripts. HideToTray is used to run HideWin.
HideWin must be compiled to allow it to receive parameters.

It's far from perfect - you can hide the same window several times. Maybe spawning GUIs would be a better solution?

Skrommel


HideToTray:

;HideToTray

SetWorkingDir,"%A_ScriptDir%"

Menu,Tray,NoStandard
Menu,Tray,Add,&Hide Active Window,HIDE
Menu,Tray,Default,&Hide active window
Menu,Tray,Add,E&xit,EXIT

START:
Gosub,GETWINDOW
Sleep,999
Goto,START

HIDE:
Run,hidewin.exe "%window%","%A_ScriptDir%"
Return

GETWINDOW:
WinGet,window0,ID,A
WinGetClass,class,ahk_id %window0%
If class<>
If class<>Shell_TrayWnd
If class<>AutoHotkey
  window=%window0%
Return

EXIT:
ExitApp


HideWin: must be compiled into HideWin.exe

;HideWin must be compiled into HideWin.exe

window=%1%
DetectHiddenWindows,On
Gosub,HIDE

START:
Gosub,READICON
Gosub,GETMAXIMIZE
Gosub,GETONTOP
Gosub,GETTRANSPARENT
Sleep,999
Goto,START

HIDE:
SetTimer,READICON,Off
Gosub,READICON
WinGetTitle,title,ahk_id %window%
Menu,Tray,Icon,%path%,1 
Menu,Tray,Tip,%info% - %title%
usermenu=UnHide
Gosub,ADDMENU
WinHide,ahk_id %window%
Return

UNHIDE:
usermenu=Hide
Gosub,ADDMENU
WinShow,ahk_id %window%
WinActivate,ahk_id %window%
SetTimer,READICON,On
Return

ADDMENU:
Menu,Tray,NoStandard
Menu,Tray,DeleteAll
Menu,Tray,Add,%usermenu%
Menu,Tray,Default,%usermenu%
Menu,Tray,Add,Maximize,MAXIMIZE
Menu,Tray,Add,OnTop,ONTOP
Menu,Tray,Add,Transparent,TRANSPARENT
If maximize=1
  Menu,Tray,Check,Maximize
Else
  Menu,Tray,UnCheck,Maximize
If ontop=1
  Menu,Tray,Check,OnTop
Else
  Menu,Tray,UnCheck,OnTop
If transparent=1
  Menu,Tray,Check,Transparent
Else
  Menu,Tray,UnCheck,Transparent
Menu,Tray,Add,&Release,RELEASE
Menu,Tray,Add,E&xit,EXIT
Return

MAXIMIZE:
If maximize=1
  WinRestore,ahk_id %window%
Else
  WinMaximize,ahk_id %window%
Gosub,GETMAXIMIZE
Gosub,ADDMENU
Return

ONTOP:
If ontop=1
  WinSet,AlwaysOnTop,Off,ahk_id %window%
Else
  WinSet,AlwaysOnTop,On,ahk_id %window%
Gosub,GETONTOP
Gosub,ADDMENU
Return

TRANSPARENT:
If transparent=1
  WinSet,Transparent,Off,ahk_id %window%
Else
  WinSet,Transparent,122,ahk_id %window%
Gosub,GETTRANSPARENT
Gosub,ADDMENU
Return

GETMAXIMIZE:
  WinGet,maximize,MinMax,ahk_id %window%
Return

GETONTOP:
WinGet,ontop,ExStyle,ahk_id %window%
Transform,ontop,BitAnd,%ontop%,0x8
If ontop<>0
  ontop=1
Else
  ontop=0
Return

GETTRANSPARENT:
WinGet,transparent,Transparent,ahk_id %window%
If transparent>0
  transparent=1
Else
  transparent=0
Return

READICON:
  WinGet,file,ProcessName,ahk_id %window%
  If file=
    Goto,EXIT
  Loop,HKEY_CURRENT_USER,Software\Microsoft\Windows\ShellNoRoam\MUICache,0,0
  {
    IfInString,A_LoopRegName,%file%
    {
      RegRead,info
      path=%A_LoopRegName%
      Break
    }
  }
Return

RELEASE:
Gosub,UNHIDE
ExitApp

EXIT:
Gosub,UNHIDE
WinClose,ahk_id %window%
ExitApp


toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Hi,
I see no reason why HideWin have to be compiled. Script code can accept parameters as well. Could you please explain that?
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
I thought so too, but running 1.ahk below produces an error unless it's compiled.

1.ahk:
Run,2.ahk test

2.ahk:
MsgBox,%1%

Skrommel

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
when you run scripts you have to use
run, autohotkey.exe 2.ahk test
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
:D Thanks!

Skrommel

Szara
  • Guests
  • Last active:
  • Joined: --
THIS is one of my very favourite scripts...ever. For its faults (requirement of 2 scripts, minimizing same window multiple times, and icon problems are all I can think of) it has been one of the handiest, most addictive scripts I've yet come across (and I've tried out plenty!)

My only problem is the aforementioned icon problems: When I try to minimize some programs, I get an error message related to the icon. For example, when trying to minimize Internet Explorer:
-------------------------
HideWin.exe
-------------------------
Error: Can't load icon.  The current thread will exit.

Specifically: @C:\Program Files\Internet Explorer\iexplore.exe,-702

      Line#
--->  019: Menu,Tray,Icon,%path%,1

-------------------------
OK
-------------------------
The only other one I've had trouble with is Spider Solitaire, and that seems to work at random.

I've tried to figure it out on my own, I've searched the forum, I just don't get what's wrong. Can you shed any light?

Again, THANK YOU!!

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I think you could add the following line to avoid such error messages (perhaps add it at near the top of the script):

Menu, Tray, UseErrorLevel

Szara
  • Guests
  • Last active:
  • Joined: --
Oh, hooray, it worked! It uses the green default icon instead of the IE icon, but that's okay for just one or two (I'm pretty picky about having distinctive icons for all my ahk scripts so they're easy to identify).

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thanks so much Chris ~ both for this tip, and for this awesome program!! I must tell you, it's made my work life easier ~ I do data input with some very poorly written software, and AHK has taken literally HOURS out of performing many of the repetitive tasks involved. I don't know WHAT I'd do without it. In fact, when I bought my first Mac, I was heartbroken to learn that this indispensable program wouldn't work with it. I've had to make do with less configurable GUI-based apps to do the things I've come to take for granted. One of the reasons I'll hang on to my Windows box. =^.^=

Junyx
  • Members
  • 124 posts
  • Last active: Nov 01 2015 06:37 PM
  • Joined: 11 Jul 2005
well, erm, you could check out this, too:
:arrow: Min2Tray

does almost the same thing and even more with just one (script-)file.
give it a try. i appreciate your reply, too!

Junyx

Szara
  • Members
  • 8 posts
  • Last active: Jul 01 2006 07:46 AM
  • Joined: 24 Jun 2006
OooooOOOOOooohhh, that one looks inCREdible! I'll most certainly give it a shot when I've got time to experiment again, and once my Vista's up and running, will let you know how it works! In the meantime, skrommel's script is the one I"m used to...there's just too much going on in my life to fiddle. :(
If I'm asking a question about AHK, it's only because I can't find the answer anywhere else. I swear, I looked!

AutoHotKey has saved me at least 8 hours a month of data entry. What has it done for you?

Junyx
  • Members
  • 124 posts
  • Last active: Nov 01 2015 06:37 PM
  • Joined: 11 Jul 2005

OooooOOOOOooohhh, that one looks inCREdible!

thanks a lot!
all for your pleasure...

there's just too much going on in my life to fiddle. :(

yeah, i know those days, too :wink:

Junyx