AutoHotkey Community

It is currently May 27th, 2012, 1:17 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: how would I do that?
PostPosted: January 20th, 2005, 12:49 am 
That script is awesome! How would I change it so it does winmove and moves it down the screen where you can't see it. (it can't go to the sides because of multiple monitors and occasionally there is a monitor on top.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2005, 1:25 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
You'll have to experiment with WinMove to see where the best place to put it is. Note that you can use negative coordinates with WinMove, which might be best in this case.

If necessary, you can query the system's multi-monitor info with SysGet. That can help find offscreen coordinates.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 20th, 2005, 5:36 pm 
I found a problem with winmove... I was able to get it to move the window off the screen and when you clicked it would "snap back" to it's original position but that still leaves the window in your taskbar which is what I'm trying to avoid...

Is there a way to have the script monitor the window and if anything changes or if it tries to close it will unhide the window?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2005, 11:38 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Quote:
leaves the window in your taskbar which is what I'm trying to avoid...
I don't know a way to reliably remove another application's taskbar button without hiding its window.

Quote:
Is there a way to have the script monitor the window and if anything changes or if it tries to close it will unhide the window?
You can detect the disappearance of a window (i.e. if it closed itself) with IfWinExist or WinWaitClose. To detect changes in a window's title or text, you can use IfWinExist, WinGetTitle, or WinGetText. Other types of changes, such as size and position, can also be detected.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Added a counter icon
PostPosted: May 13th, 2009, 9:57 am 
Offline

Joined: November 27th, 2008, 10:15 am
Posts: 16
Location: Johannesburg, South Africa
Instead of having the regular aHk H-icon for the MinToTrayMenu script, I figured it would be a nice idea to have a counter icon - i.e. 0 to >9 to indicate (at a glance) whether there are any windows hidden to the tray menu, and if so, how many are hidden.
Thanks to Skwire for the icons :D
My code is commented by ; Talisman
Also, I changed the hotkeys to Win+Delete and Win+Alt+Delete to indicate what you are doing to the window - i.e. deleting them from the visual interface :-)
Also, the number icons are available are available at http://www.autohotkey.net/~Talisman/Graphics/Icons.zip
Just unzip them to %A_ScriptDir%\Icons for the script to see them.

Code:
; Minimize Window to Tray Menu
; http://www.autohotkey.com
; This script assigns a hotkey of your choice to hide any window so that
; it becomes an entry at the bottom of the script's tray menu.  Hidden
; windows can then be unhidden individually or all at once by selecting
; the corresponding item on the menu.  If the script exits for any reason,
; all the windows that it hid will be unhidden automatically.

; CHANGES:
; March, 2009 (changes provided by Talisman)
; - Added a new function to display a number-icon as the tray-icon to indicate at a glance how many windows are hidden to tray-menu.
; July 22, 2005 (changes provided by egilmour):
; - Added new hotkey to unhide the last hidden window (Win+U)
;
; November 3, 2004 (changes provided by trogdor):
; - Program manager is prevented from being hidden.
; - If there is no active window, the minimize-to-tray hotkey will have
;   no effect rather than waiting indefinitely.
;
; October 23, 2004:
; - The taskbar is prevented from being hidden.
; - Some possible problems with long window titles have been fixed.
; - Windows without a title can be hidden without causing problems.
; - If the script is running under AHK v1.0.22 or greater, the
;   maximum length of each menu item is increased from 100 to 260.

; CONFIGURATION SECTION: Change the below values as desired.
; TALISMAN: addition to show the tray icon menu.
mwt_ShowMenu = !#HOME

; This is the maximum number of windows to allow to be hidden (having a
; limit helps performance):
mwt_MaxWindows = 50

; This is the hotkey used to hide the active window:
;mwt_Hotkey = #h  ; Win+H
mwt_Hotkey = #Delete  ; Win+Insert

; This is the hotkey used to unhide the last hidden window:
;mwt_UnHotkey = #u  ; Win+U
mwt_UnHotkey = #!Delete  ; Win+Alt+Delete

; If you prefer to have the tray menu empty of all the standard items,
; such as Help and Pause, use N.  Otherwise, use Y:
mwt_StandardMenu = Y

; These next few performance settings help to keep the action within the
; #HotkeyModifierTimeout period, and thus avoid the need to release and
; press down the hotkey's modifier if you want to hide more than one
; window in a row.  These settings are not needed you choose to have the
; script use the keyboard hook via #InstallKeybdHook or other means:
#HotkeyModifierTimeout 100
; #NoTrayIcon
SetWinDelay 10
SetKeyDelay 0

#SingleInstance force ; Allow only one instance of this script to be running.

; END OF CONFIGURATION SECTION (do not make changes below this point
; unless you want to change the basic functionality of the script).

Hotkey, %mwt_Hotkey%, mwt_Minimize
Hotkey, %mwt_UnHotkey%, mwt_UnMinimize
Hotkey, %mwt_ShowMenu%, mwt_ShowTrayMenu

; If the user terminates the script by any means, unhide all the
; windows first:
OnExit, mwt_RestoreAllThenExit

Menu, Tray, Icon, %A_ScriptDir%\Icons\0.ico
StringTrimRight,applicationname,A_ScriptName,4
Menu,Tray,NoStandard
Menu,Tray,DeleteAll
Menu,Tray,Add,%applicationname%, RELOAD

if mwt_StandardMenu = Y
   Menu, Tray, Add
else
{
   Menu, Tray, NoStandard
   Menu, Tray, Add, E&xit and Unhide All, mwt_RestoreAllThenExit
}
Menu, Tray, Add, &Unhide All Hidden Windows, mwt_RestoreAll
Menu,Tray,Add,E&xit,EXIT
Menu, Tray, Add  ; Another separator line to make the above more special.
Menu,Tray,Default,%applicationname%
Menu,Tray,Tip,%applicationname%

if a_AhkVersion =   ; Since it's blank, version is older than 1.0.22.
   mwt_MaxLength = 100
else
   mwt_MaxLength = 260  ; Reduce this to restrict the width of the menu.

mwt_WindowCount = 0    ; Initialise

return  ; End of auto-execute section.


mwt_Minimize:
if mwt_WindowCount >= %mwt_MaxWindows%
{
   MsgBox No more than %mwt_MaxWindows% may be hidden simultaneously.
   return
}

; Set the "last found window" to simplify and help performance.
; Since in certain cases it is possible for there to be no active window,
; a timeout has been added:
WinWait, A,, 2
if ErrorLevel <> 0  ; It timed out, so do nothing.
   return

; Otherwise, the "last found window" has been set and can now be used:
WinGet, mwt_ActiveID, ID
WinGetTitle, mwt_ActiveTitle
WinGetClass, mwt_ActiveClass
if mwt_ActiveClass in Shell_TrayWnd,Progman
{
   MsgBox The desktop and taskbar cannot be hidden.
   return
}
; Because hiding the window won't deactivate it, activate the window
; beneath this one (if any). I tried other ways, but they wound up
; activating the task bar.  This way sends the active window (which is
; about to be hidden) to the back of the stack, which seems best:
Send, !{esc}
; Hide it only now that WinGetTitle/WinGetClass above have been run (since
; by default, those commands cannot detect hidden windows):
WinHide

; If the title is blank, use the class instead.  This serves two purposes:
; 1) A more meaningful name is used as the menu name.
; 2) Allows the menu item to be created (otherwise, blank items wouldn't
;    be handled correctly by the various routines below).
if mwt_ActiveTitle =
   mwt_ActiveTitle = ahk_class %mwt_ActiveClass%
; Ensure the title is short enough to fit. mwt_ActiveTitle also serves to
; uniquely identify this particular menu item.
StringLeft, mwt_ActiveTitle, mwt_ActiveTitle, %mwt_MaxLength%

; In addition to the tray menu requiring that each menu item name be
; unique, it must also be unique so that we can reliably look it up in
; the array when the window is later unhidden.  So make it unique if it
; isn't already:
Loop, %mwt_MaxWindows%
{
   if mwt_WindowTitle%a_index% = %mwt_ActiveTitle%
   {
      ; Match found, so it's not unique.
      ; First remove the 0x from the hex number to conserve menu space:
      StringTrimLeft, mwt_ActiveIDShort, mwt_ActiveID, 2
      StringLen, mwt_ActiveIDShortLength, mwt_ActiveIDShort
      StringLen, mwt_ActiveTitleLength, mwt_ActiveTitle
      mwt_ActiveTitleLength += %mwt_ActiveIDShortLength%
      mwt_ActiveTitleLength += 1 ; +1 the 1 space between title & ID.
      if mwt_ActiveTitleLength > %mwt_MaxLength%
      {
         ; Since menu item names are limted in length, trim the title
         ; down to allow just enough room for the Window's Short ID at
         ; the end of its name:
         TrimCount = %mwt_ActiveTitleLength%
         TrimCount -= %mwt_MaxLength%
         StringTrimRight, mwt_ActiveTitle, mwt_ActiveTitle, %TrimCount%
      }
      ; Build unique title:
      mwt_ActiveTitle = %mwt_ActiveTitle% %mwt_ActiveIDShort%
      break
   }
}

; First, ensure that this ID doesn't already exist in the list, which can
; happen if a particular window was externally unhidden (or its app unhid
; it) and now it's about to be re-hidden:
mwt_AlreadyExists = n
Loop, %mwt_MaxWindows%
{
   if mwt_WindowID%a_index% = %mwt_ActiveID%
   {
      mwt_AlreadyExists = y
      break
   }
}

; Add the item to the array and to the menu:
if mwt_AlreadyExists = n
{
   Menu, Tray, add, %mwt_ActiveTitle%, RestoreFromTrayMenu
   mwt_WindowCount += 1
   Loop, %mwt_MaxWindows%  ; Search for a free slot.
   {
      ; It should always find a free slot if things are designed right.
      if mwt_WindowID%a_index% =  ; An empty slot was found.
      {
         mwt_WindowID%a_index% = %mwt_ActiveID%
         mwt_WindowTitle%a_index% = %mwt_ActiveTitle%
         break
      }
   }
   SetIcon(mwt_WindowCount) ; Talisman - addition to show the tray icon menu.
}
return


RestoreFromTrayMenu:
Menu, Tray, delete, %A_ThisMenuItem%
; Find window based on its unique title stored as the menu item name:
Loop, %mwt_MaxWindows%
{
   if mwt_WindowTitle%a_index% = %A_ThisMenuItem%  ; Match found.
   {
      StringTrimRight, IDToRestore, mwt_WindowID%a_index%, 0
      WinShow, ahk_id %IDToRestore%
      WinActivate ahk_id %IDToRestore%  ; Sometimes needed.
      mwt_WindowID%a_index% =  ; Make it blank to free up a slot.
      mwt_WindowTitle%a_index% =
      mwt_WindowCount -= 1
      SetIcon(mwt_WindowCount) ; Talisman - addition to show the tray icon menu.
      break
   }
}
return

mwt_ShowTrayMenu:
   DetectHiddenWindows, On
   SetTitleMatchMode, 2
;   Loop  ; Loop through the applications to find either the .exe or the AutoHotkey.exe that matches this script.
;   {
;      
;   }
   hWnd := WinExist("MinimizeToTrayMenu")
   PostMessage, 1028, 0, 0x204, , ahk_id %hWnd% ; WM_RBUTTONDOWN
   PostMessage, 1028, 0, 0x205, , ahk_id %hWnd% ; WM_RBUTTONUP
Return

;; This will pop the last minimized window off the stack and unhide it.
mwt_UnMinimize:
;; Make sure there's something to unhide.
if mwt_WindowCount > 0
{
   ;; Get the id of the last window minimized and unhide it
   StringTrimRight, IDToRestore, mwt_WindowID%mwt_WindowCount%, 0
   WinShow, ahk_id %IDToRestore%
   WinActivate ahk_id %IDToRestore%
   
   ;; Get the menu name of the last window minimized and remove it
   StringTrimRight, MenuToRemove, mwt_WindowTitle%mwt_WindowCount%, 0
   Menu, Tray, delete, %MenuToRemove%
   
   ;; clean up our 'arrays' and decrement the window count
   mwt_WindowID%mwt_WindowCount% =
   mwt_WindowTitle%mwt_WindowCount% =
   mwt_WindowCount -= 1
   SetIcon(mwt_WindowCount) ; Talisman - addition to show the tray icon menu.
}
return


mwt_RestoreAllThenExit:
Gosub, mwt_RestoreAll
ExitApp  ; Do a true exit.


mwt_RestoreAll:
Loop, %mwt_MaxWindows%
{
   if mwt_WindowID%a_index% <>
   {
      StringTrimRight, IDToRestore, mwt_WindowID%a_index%, 0
      WinShow, ahk_id %IDToRestore%
      WinActivate ahk_id %IDToRestore%  ; Sometimes needed.
      ; Do it this way vs. DeleteAll so that the sep. line and first
      ; item are retained:
      StringTrimRight, MenuToRemove, mwt_WindowTitle%a_index%, 0
      Menu, Tray, delete, %MenuToRemove%
      mwt_WindowID%a_index% =  ; Make it blank to free up a slot.
      mwt_WindowTitle%a_index% =
      mwt_WindowCount -= 1
   }
   SetIcon(mwt_WindowCount) ; Talisman - addition to show the tray icon menu.
   if mwt_WindowCount = 0
      break
}
return

EXIT:
  ExitApp
Return

RELOAD:
   Reload
Return

 ; Talisman - Start SetIcon function: addition to show the tray icon menu.
SetIcon(IconNumber) {
   If (IconNumber > 9)
      Menu, Tray, Icon, %A_ScriptDir%\Icons\g9.ico, 1
   Else
      Menu, Tray, Icon, %A_ScriptDir%\Icons\%IconNumber%.ico, 1
}
; Talisman - End SetIcon function


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 1st, 2009, 6:12 am 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
@Talismaniac: the link is not working. do you have an alternate link?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2009, 4:47 pm 
Offline

Joined: November 27th, 2008, 10:15 am
Posts: 16
Location: Johannesburg, South Africa
badmojo wrote:
@Talismaniac: the link is not working. do you have an alternate link?


Apologies... I've done a bit of cleanup and removed the icons in error... I'll put them up again later.
Check again in 24 hours...

Tal


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2009, 3:12 am 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
@Talismaniac: thanks for the wonderful script. i was wondering if you could make it possible for the users to select different sets of icons from the context menu?

e.g. Folder Icons\Dark <- contains dark themed icons
Folder Icons\Light <- contains light themed icons

so on and so forth, this will give more choice to the user. i hope you will consider this.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Icons link
PostPosted: January 11th, 2010, 8:43 am 
Offline

Joined: November 27th, 2008, 10:15 am
Posts: 16
Location: Johannesburg, South Africa
@ badmojo...
Sorry about the delay... :-/ Too much to do and not enough time to do it in :-)
Anyway... the link to the icons is up and working --> http://www.autohotkey.net/~Talisman/Graphics/Icons.zip

Hehe... don't thank me for the script... I just modified it :-)

I'll have a look at "themed" icons... using different directories.

Tal

_________________
Keep it Real
Talismaniac
http://www.autohotkey.net/~Talisman


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2010, 8:27 am 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
@Talismaniac: thanks again, the icons look very nice..


Report this post
Top
 Profile  
Reply with quote  
 Post subject: ~
PostPosted: March 23rd, 2010, 3:50 pm 
Offline
User avatar

Joined: December 30th, 2009, 10:30 pm
Posts: 160
Location: Worcester, Massachusetts

_________________
★★★ Email me at berban at aim full stop com ★★★


Last edited by berban on November 14th, 2010, 1:52 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2010, 11:12 am 
Offline

Joined: August 30th, 2010, 9:05 pm
Posts: 21
The script is one of the coolest i have - icon numbering is genial. Work like a charm on my Vista x64 :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Bing [Bot] and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group