Jump to content
Sign in to follow this  
sheck

Hide To Tray

Recommended Posts

It's hard to describe for me, too strange. Anyway The Bat! seems to resist in some way.

I might install it later and try see what's going on.

Live and Learn, 'cause Knowledge is Super Power.

Share this post


Link to post
Share on other sites

:lmao: Yes, it's true. The Bat window cannot be hidden using my app. It has the same effect as minimizing a window.

But The Bat has an option to minimize to system tray, you can use that instead.


Live and Learn, 'cause Knowledge is Super Power.

Share this post


Link to post
Share on other sites

Made this for myself for work. You can hide any active window to tray menu, then unhide it at any time.

I'm pretty new to AutoIt so there might be better ways of doing this. I'm open to suggestions.

I forgot to mention that you need Beta version of AutoIt for this script to work.

Awesome... works perfectly for what I needed. Nice work!

Share this post


Link to post
Share on other sites

Again, thanks sheck!

I'm still playing with it.

I also have an app with which it is funky - Total Commander. It hides the window and the window name ("Total Commander 6.54Publicß1 - Daniel M. Greenberg") appears in the list but does not restore on click (so far, all other windows have worked fine). In Windows Task Manager, TOTALCMD appears in the process list but not in the application list. I end the process and restart TC (and don't use hide-to-tray) on it again.

I haven't worked with Auto-It long enough to know how to debug the script properly - i.e. trace variables in SciTe. When I get a few hourse, I'll play with it.

Dan

Share this post


Link to post
Share on other sites

This is killer! I'm a big fan of a little app called PowerMenu. I would have never thoght of rewriting it, untill I saw this... But I thought it would be fun to see how much of it's functrionallty I could duplicate using this as a base.

It seems to work really well, I only had a little time to play with it, and didn't do much testing. So I'm sure there are some bugs.

None-the-less:

#include <GUIConstants.au3>
opt("WinTitleMatchMode", 4)
opt("TrayMenuMode", 1)

Global $itemnum, $enum, $msg, $num, $proc, $gett, $gettif, $itemnum2, $recountt, $recount2, $bit, $state, $title, $exitc, $proclist, $upcount, $procupcount, $hUI_Popup
Dim $hLastTopped = ''
Dim $hLastTransed = ''
Dim $trayitem1[100]
Dim $procitem[100]
Dim $trayrec[100]
Dim $proclist[100][2]

$execpath = @AutoItExe

$string1 = StringInStr($execpath, "\", 0, -1)
$string2 = StringTrimLeft($execpath, $string1)

$proclist = ProcessList($string2)

Do
    $upcount = $upcount + 1
    If $proclist[$upcount][0] = $string2 Then
        $procupcount = $procupcount + 1
    EndIf
Until $upcount = $proclist[0][0]

If $procupcount > 1 Then Exit

HotKeySet("{F11}", "Menu")


$trayitem2 = TrayCreateItem ("Exit")
TrayCreateItem ("")

TraySetState ()

TrayTip("Hide To Tray - Hot Key", "Press F11 to view HTT Menu.", 5)

While 1
    $msg = TrayGetMsg ()
    Select
        Case $msg = $trayitem2
            Exit
    EndSelect
    If $msg > 0 Then restore()
WEnd

Func hide()  ; <-- To hide active window
    $title = ""
    $proc = WinGetProcess("active", "")
    If $itemnum > 0 Then
        Do
            $state = WinGetState("active", "")
            If Not BitAND($state, 2) Then
                recount()
                Return
            EndIf
            $num = $num + 1
            If $procitem[$num] = $proc Then
                $gettif = TrayItemGetText ($trayitem1[$num])
                WinSetTitle($gettif & $procitem[$num], "", $gettif)
                TrayItemDelete ($trayitem1[$num])
                $procitem[$num] = 0
            EndIf
        Until $num = $itemnum
    EndIf
    recount()
    $num = 0
    $title = WinGetTitle("active", "")
    If @error Or $title = 1 Or $title = "" Then
        Return
    EndIf
    $itemnum = $itemnum + 1
    WinSetTitle("active", "", $title & $proc)
    WinSetState("active", "", @SW_HIDE)
    $trayitem1[$itemnum] = TrayCreateItem ($title)
    $procitem[$itemnum] = $proc
    $bit = $bit + 1
EndFunc  ;==>hide

Func ontop()  ; <-- Sets win on top
    $hLastTopped = WinGetHandle("active")
    WinSetOnTop("active", "", 1)
EndFunc  ;==>ontop

Func semitrans()
    $hLastTransed = WinGetHandle("active")
    WinSetTrans("active", "", 175)
EndFunc  ;==>semitrans

Func Menu()
    HotKeySet("{F11}", "killmenu");Reset so menu is only called once
    
    HotKeySet("1", "runhide");hide
    HotKeySet("2", "runontop");always on top
    HotKeySet("3", "runsemitrans");makse win semi transparent
    HotKeySet("4", "reset");resets all wins defaults
    HotKeySet("5", "exithtt");exits hide to tray
    
;now set the same for the numpad
    HotKeySet("{NUMPAD1}", "runhide");hide
    HotKeySet("{NUMPAD2}", "runontop");always on top
    HotKeySet("{NUMPAD3}", "runsemitrans");makse win semi transparent
    HotKeySet("{NUMPAD4}", "reset");resets all wins defaults
    HotKeySet("{NUMPAD5}", "exithtt");exits hide to tray
    
    
    
;let's make a 10 sec popup option menu
    $hUI_Popup = GUICreate("", 400, 150, Default, Default, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    GUISetBkColor(0xBCD2EE, Default)
    
    GUICtrlCreateLabel("1: Hide current window", 8, 10, 427, 57)
    GUICtrlSetFont(Default, 14, 1000)
    
    GUICtrlCreateLabel("2: Set current window on top", 8, 30, 427, 57)
    GUICtrlSetFont(Default, 14, 1000)
    
    GUICtrlCreateLabel("3: Make current window semi-transparent", 8, 50, 427, 57)
    GUICtrlSetFont(Default, 14, 1000)
    
    GUICtrlCreateLabel("4: Reset all windows to default settings", 8, 70, 427, 57)
    GUICtrlSetFont(Default, 14, 1000)
    
    GUICtrlCreateLabel("5: Exit HTT (resets all windows)", 8, 90, 427, 57)
    GUICtrlSetFont(Default, 14, 1000)
    
    GUICtrlCreateLabel("F11: Cancel (Close HTT menu)", 8, 120, 427, 57)
    GUICtrlSetFont(Default, 13, 1000)
    
    WinSetTrans($hUI_Popup, "", 200)
    
    GUISetState(@SW_SHOW)
    
    Sleep(10000)
    
    killmenu();delets menu, kills hkey regs
EndFunc  ;==>Menu

Func restore(); <-- Unhides window
    If $itemnum < 1 Then Return
    $itemnum2 = $itemnum
    Do
        Select
            Case $msg = $trayitem1[$itemnum2]
                $enum = $itemnum2
        EndSelect
        $itemnum2 = $itemnum2 - 1
    Until $itemnum2 = 0
    $gett = TrayItemGetText ($trayitem1[$enum])
    WinSetState($gett & $procitem[$enum], "", @SW_SHOW)
    WinSetTitle($gett & $procitem[$enum], "", $gett)
    TrayItemDelete ($trayitem1[$enum])
    $procitem[$enum] = 0
    recount()
    Return
EndFunc  ;==>restore

Func recount(); <-- Removes and recalculates variable and tray menu text
    If $itemnum = 0 Then Return
    $recountt = 0
    $recount2 = 0
    $bit = 0
    Do
        $recountt = $recountt + 1
        $trayrec[$recountt] = TrayItemGetText ($trayitem1[$recountt])
    Until $recountt = $itemnum
    $recountt = 0
    Do
        $recountt = $recountt + 1
        If $procitem[$recountt] <> 0 Then
            $bit = $bit + 1
        EndIf
    Until $recountt = $itemnum
    If $bit = 0 Then
        $itemnum = $bit
        Return
    EndIf
    $recountt = 0
    Do
        $recountt = $recountt + 1
        $recount2 = $recount2 + 1
        If $procitem[$recountt] = 0 Then
            $recount2 = $recount2 + 1
        EndIf
        If $recount2 < $itemnum Or $recount2 = $itemnum Then
            $procitem[$recountt] = $procitem[$recount2]
        EndIf
    Until $recount2 = $itemnum Or $recount2 > $itemnum
    $recountt = 0
    Do
        $recountt = $recountt + 1
        TrayItemDelete ($trayitem1[$recountt])
    Until $recountt = $itemnum + 5
    $recountt = 0
    $recount2 = 0
    Do
        $recount2 = $recount2 + 1
        $recountt = $recountt + 1
        If $trayrec[$recountt] = "" Then
            $recount2 = $recount2 + 1
        EndIf
        If $recount2 < $itemnum Or $recount2 = $itemnum Then
            $trayitem1[$recountt] = TrayCreateItem ($trayrec[$recount2])
        EndIf
    Until $recount2 = $itemnum Or $recount2 > $itemnum
    $itemnum = $bit
    Return
EndFunc  ;==>recount

Func runhide()
    killmenu()
    
    hide()
EndFunc  ;==>runhide

Func runontop()
    killmenu()
    
    If $hLastTopped <> '' Then WinSetOnTop($hLastTopped, "", 0);removes 'top' from last toped window
    ontop()
EndFunc  ;==>runontop

Func runsemitrans()
    killmenu()
    
    If $hLastTransed <> '' Then WinSetTrans($hLastTransed, "", 255);resets last win set to trans
    semitrans()
EndFunc  ;==>runsemitrans

Func killmenu();removes hkey registration, delets menu
    HotKeySet("{F11}", "Menu");RReenable F11 menu calls
    
    HotKeySet("1");called with no second parama, unregs hkey.
    HotKeySet("{NUMPAD1}")
    HotKeySet("2")
    HotKeySet("{NUMPAD2}")
    HotKeySet("3")
    HotKeySet("{NUMPAD3}")
    HotKeySet("4")
    HotKeySet("{NUMPAD4}")
    HotKeySet("5")
    HotKeySet("{NUMPAD5}")
    HotKeySet("{ESC}")
    
    
    
    GUIDelete($hUI_Popup)
    Sleep(20);grrr
EndFunc  ;==>killmenu

Func reset()
    killmenu()
    
    If $itemnum > 0 Then
            Do
                $exitc = $exitc + 1
                $gett = TrayItemGetText ($trayitem1[$exitc])
                TrayItemDelete ($trayitem1[$exitc])
                WinSetState($gett & $procitem[$exitc], "", @SW_SHOW)
                WinSetTitle($gett & $procitem[$exitc], "", $gett)
            Until $exitc = $itemnum
    EndIf
    
    If $hLastTopped <> '' Then WinSetOnTop($hLastTopped, "", 0);removes 'top' from last toped window
    If $hLastTransed <> '' Then WinSetTrans($hLastTransed, "", 255);resets last win set to trans
EndFunc  ;==>reset

Func exithtt()
    Exit
EndFunc  ;==>exithtt

Func OnAutoItExit(); <-- Unhides all windows that have been hidden with this app on exit
    reset()
EndFunc  ;==>OnAutoItExit

Share this post


Link to post
Share on other sites

This is killer! I'm a big fan of a little app called PowerMenu. I would have never thoght of rewriting it, untill I saw this... But I thought it would be fun to see how much of it's functrionallty I could duplicate using this as a base.

It seems to work really well, I only had a little time to play with it, and didn't do much testing. So I'm sure there are some bugs.

I like it. It's neat. Add a few more functions and you can sell it. :lmao:

As for the windows that don't want to hide or restore, I will look into this and see what I can come up with. As fas as I know right now, some applications just don't like to be forced to hide and there is not much one can do about it with Auto it, but as I said I will see what I can come up with.

Edited by sheckandar

Live and Learn, 'cause Knowledge is Super Power.

Share this post


Link to post
Share on other sites

I tried to combine the script with mine (It's a personal script -- Will not be released) and I got this error(attached) It gives this error with normal, and beta autoit. It happends when ever I use #include on it, and if I paste the code in it gives me a While withought WEnd. How could I implement it in? (Script may be supplied if you PM me or request it here)

run tidy on your script. that should find where your mismatched level is. That's the best advice without seeing any code...

Share this post


Link to post
Share on other sites

2 things

1 I PM'ed the maker of this script and he got it working

2 what's tidy?


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

OK, I figured out why The Bat! bottom part cannot be hidden - it's actually a separate window that runs under the same proccess. When you hide the main window the one in taskbar is not recognised as the part of the main window thus is not hidden. Alot of applications that are programmed in VB do that.

I'm currently working on solution for that, but no luck yet. :lmao:

Edited by sheckandar

Live and Learn, 'cause Knowledge is Super Power.

Share this post


Link to post
Share on other sites

I'm running the latest beta (3.1.1.109) and, from a straight copy/paste, I'm getting these errors on a syntax check:

F:\My Scripts\My Downloadeds\Hide Active Win.au3(3,22) : ERROR: Opt() called with illegal argument 1: "TrayMenuMode"

opt("TrayMenuMode", 1)

~~~~~~~~~~~~~~~~~~~~~^

F:\My Scripts\My Downloadeds\Hide Active Win.au3(28,36) : ERROR: TrayCreateItem(): undefined function.

$trayitem2 = TrayCreateItem ("Exit")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

F:\My Scripts\My Downloadeds\Hide Active Win.au3(31,15) : ERROR: TraySetState(): undefined function.

TraySetState ()

~~~~~~~~~~~~~~^

F:\My Scripts\My Downloadeds\Hide Active Win.au3(47,48) : ERROR: TrayItemGetText(): undefined function.

$gettif = TrayItemGetText ($trayitem1[$num])

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

F:\My Scripts\My Downloadeds\Hide Active Win.au3(49,37) : ERROR: TrayItemDelete(): undefined function.

TrayItemDelete ($trayitem1[$num])

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

F:\My Scripts\My Downloadeds\Hide Active Win.au3(140,21) : ERROR: TrayGetMsg(): undefined function.

$msg = TrayGetMsg ()

~~~~~~~~~~~~~~~~~~~^

One thing I noticed, apart from missing functions, is that you've got a While/Wend place between the Functions near the end. Should that loop have it's own function name?

EDIT: I looked through the Beta files' Help file and found the TRAY... info, but I need to get SciTe to use those files for compiling/syntax checking, it would appear.

Edited by Xander

Share this post


Link to post
Share on other sites

I'm running the latest beta (3.1.1.109) and, from a straight copy/paste, I'm getting these errors on a syntax check:

One thing I noticed, apart from missing functions, is that you've got a While/Wend place between the Functions near the end. Should that loop have it's own function name?

EDIT: I looked through the Beta files' Help file and found the TRAY... info, but I need to get SciTe to use those files for compiling/syntax checking, it would appear.

The code is complete and fully functional. If you are having diffculties : check that you have the latest Beta version and Scite defenition files and make sure that you press Alt+F5 when running Beta files.


Live and Learn, 'cause Knowledge is Super Power.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...