AutoHotkey Community

It is currently May 26th, 2012, 7:19 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: June 2nd, 2009, 2:54 pm 
Offline

Joined: June 2nd, 2009, 2:47 pm
Posts: 17
I created this bosskey app for the guys at my school, It is based off of the minimize to tray script here: http://www.autohotkey.com/docs/scripts/MinimizeToTrayMenu.htm

I figured I'd post it here so others can get some use out of it and maybe it could be improved.

Code:
#Persistent
#SingleInstance force
RegRead, saved, HKEY_LOCAL_MACHINE, SOFTWARE\PrintSpooler, Saved
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\PrintSpooler, Author, Jordan Slaman

paused = false

Gui, Add, Text, x6 y13 w300 h30 +Center, This handy application hides the active window when you press a hotkey. You can unhide it from the tray or with a hotkey.

Gui, Add, DropDownList, x6 y53 w150 h21 r4 vhidekey, Alt & X||Right Shift & /|Middle Mouse Button|Right & Left Click
Gui, Add, Text, x166 y53 w140 h20 , Hide the active window

Gui, Add, DropDownList, x6 y83 w150 h21 r4 vunhidekey, Alt & C||Right Shift & .|Ctrl & Middle Mouse Button|Left Ctrl & Esc
Gui, Add, Text, x166 y83 w140 h20 , Show the last hidden window

Gui, Add, CheckBox, x6 y113 w300 h20 vspace, Send spacebar on hide (Pause hotkey in many applications)
Gui, Add, Button, x116 y143 w80 h20 gOptions, OK
Gui, Add, Text, x6 y143 w100 h20 , Saved: %saved%

Gui, Show, x509 y272 h175 w318, PrintSpooler 9.05 | Config

return

GuiClose:
ExitApp
return

Options:
Gui, Submit
ready = true

if hidekey = Alt & X
{
mwt_Hotkey = !x
}

if hidekey = Right Shift & /
{
mwt_Hotkey = >+/
}

if hidekey = Middle Mouse Button
{
mwt_Hotkey = MButton
}

if hidekey = Right & Left Click
{
mwt_Hotkey = ~RButton & ~LButton
}

if unhidekey = Alt & C
{
mwt_UnHotkey = !c
}

if unhidekey = Right Shift & .
{
mwt_UnHotkey = >+.
}

if unhidekey = Ctrl & Middle Mouse Button
{
mwt_UnHotkey = ^MButton
}

if unhidekey = Left Ctrl & Esc
{
mwt_UnHotkey = LCtrl & Esc
}
   

;TrayTip, PrintSpooler 9.05 Beta, This version may be unstable.`nEmail bugs to Jordan Slaman.`njordan.slaman@gmail.com, 2, 1
;if saved >= 2
;{
;Sleep, 3000
;TrayTip, PrintSpooler 9.05 Beta, Jordan Slaman has saved you %saved% times., 2, 1
;}

mwt_MaxWindows = 50

mwt_StandardMenu = N

#HotkeyModifierTimeout 100
SetWinDelay 10
SetKeyDelay 0

Hotkey, %mwt_Hotkey%, mwt_Minimize
Hotkey, %mwt_UnHotkey%, mwt_UnMinimize


OnExit, mwt_RestoreAllThenExit


if mwt_StandardMenu = Y
   Menu, Tray, Add

else
{
   Menu, Tray, NoStandard
   Menu, Tray, Add, P&ause, Pause
   Menu, Tray, Add, E&xit, mwt_RestoreAllThenExit
   ;Menu, Tray, Icon, %A_WinDir%\SYSTEM32\PRINTUI.DLL, 132, 1
   if A_IsCompiled = 1
   {
   Menu, Tray, Icon, %A_ScriptName%, , 1
   }
}
Menu, Tray, Add, &Show All Hidden Windows, mwt_RestoreAll
Menu, Tray, Add 
Menu, Tray, Tip, 1 document(s) pending for %A_UserName%

if a_AhkVersion =
   mwt_MaxLength = 100
else
   mwt_MaxLength = 260  ; Reduce this to restrict the width of the menu.

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
}


if space = 1
{
Send, {Space}
}

Send, !{esc}
WinHide
saved := ++saved

if mwt_ActiveTitle =
   mwt_ActiveTitle = ahk_class %mwt_ActiveClass%

StringLeft, mwt_ActiveTitle, mwt_ActiveTitle, %mwt_MaxLength%

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
      }
   }
}
return

Pause:
if paused = true
{
   Pause, Off
   Suspend, Off
   Menu, Tray, Uncheck, P&ause
   Send, !{esc}
   paused = false
} else {
   Suspend, On
   Menu, Tray, Check, P&ause
   paused = true
   Send, !{esc}
   Pause, On
}
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
      break
   }
}
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
}
return


mwt_RestoreAllThenExit:
Gosub, mwt_RestoreAll
RegWrite, REG_DWORD, HKEY_LOCAL_MACHINE, SOFTWARE\PrintSpooler, Saved, %saved%
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
   }
   if mwt_WindowCount = 0
      break
}
return

return


I compile it with an icon.
The icon is here: http://www.filedropper.com/printui132
The Compiled code is here: http://www.filedropper.com/printspooler905


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2009, 3:02 pm 
Offline

Joined: June 2nd, 2009, 2:47 pm
Posts: 17
Oh, and if you want everything, that's here: (Removed dead link)

Edit: You can find the latest here: http://drop.io/printspooler


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Scratch and 17 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