!panic - a program that hides windows from the screen

Модератор: Злобный

Ответить
Аватара пользователя
rageX
Старожил
Сообщения: 1076
Зарегистрирован: Пт май 06, 2005 18:10

!panic - a program that hides windows from the screen

Сообщение rageX »

decided to post this program as an introduction to what can be easily accomplished with autohotkey.
Inspired by my management who started catching me online at work to much :laugh: .

Description:
!panic runs as a tray icon and hides selective windows with a middle mouse click ;) .

How to:
1) Middle click: hide all windows
2) ctrl+space: brings a gui with a list of hidden windows with an option to restore all or single items.
3) right click tray icon to specify which windows should be hidden: by title - will hide windows by title, by class - will hide by type of application(i guess).
For instance if you add any FireFox window by class no matter how many FF windows are open, all will be hidden when you mid click.

Keep in mind that configuration file will be created in !Panic's directory.

exe file can be found here: !Panic.
App source code:

Код: Выделить всё

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance Force
SetBatchLines -1


;----------------------------------------------------------------
;build menu
;----------------------------------------------------------------
Menu tray, NoStandard
Menu tray, add
Menu tray, add, Add by Title, by_Title
Menu tray, add, Add by Class, by_Class
Menu tray, add

Menu tray, add, Quit, Exit

;----------------------------------------------------------------
;build GUI
;----------------------------------------------------------------
Gui Add, ListView, x-4 y0 w210 h320 gSelected, Links
Gui Add, Button, x0 y321 w157 h30, Restore All
Gui Add, Button, x156 y321 w50 h30, Clear
Gui +AlwaysOnTop
return

;----------------------------------------------------------------
;hide windows
;----------------------------------------------------------------
MButton::
IfNotExist config.txt
   {
   MsgBox You have to specify which windows to hide, before you can proceed.`nRight click Panics tray icon to do that.
   return
}
;create group of windows to hide
loop read, config.txt
   GroupAdd hideGroup, %A_LoopReadLine%
 
; GroupAdd hideGroup, ahk_class IEFrame
; GroupAdd hideGroup, ahk_class MozillaUIWindowClass
WinGet IDarray, list, ahk_group hideGroup

Loop %IDarray%   {
   ;get current window ID
   ID := IDarray%A_Index%

   ;get title
   WinGetTitle address, ahk_id %ID%
   
   ;add to list view
   LV_Add("", address)
   FullList .= address . "`n"
}
;hide all
WinHide ahk_group hideGroup
return

;----------------------------------------------------------------
;toggle GUI
;----------------------------------------------------------------
~^space::
IfWinNotExist !Panic
   Gui Show, x293 y125 h352 w206, !Panic
else
   WinHide !Panic
Return

GuiClose:
Gui Hide
return

;----------------------------------------------------------------
;restore all hidden windows
;----------------------------------------------------------------
ButtonRestoreAll:
LV_Delete()
FullList =
WinShow ahk_group hideGroup
WinHide !Panic
return

;----------------------------------------------------------------
;restore by title on double click
;----------------------------------------------------------------
Selected:
Gui Submit, NoHide
if (A_GuiEvent = "DoubleClick") {
   LV_GetText(toBeRestored, A_EventInfo)
   WinShow %toBeRestored%
   
   StringReplace FullList, FullList, %toBeRestored%`n
   LV_Delete()

   ;reload list content
   loop parse, FullList, `n
      LV_Add("", A_LoopField)
}
return

;----------------------------------------------------------------
;clear all
;----------------------------------------------------------------
ButtonClear:
LV_Delete()
FullList =
WinHide !Panic
return

;----------------------------------------------------------------
by_Title:
   TrayTip Add Item by Title, Activate window that you would like to add.`n Press Enter when done., 10, 1
   KeyWait enter, D
   TrayTip
   WinGetTitle addMe, A
   
   fileRead file, config.txt
   if !InStr(file, addMe . "`r`n")
      FileAppend %addMe%`n, config.txt
      
return
;----------------------------------------------------------------
by_Class:
   TrayTip Add Item by Class, Activate window that you would like to add.`n Press Enter when done., 10, 1
   KeyWait enter, D
   TrayTip
   WinGetClass addMe, A
   
   fileRead file, config.txt
   if !InStr(file, "ahk_class " . addMe . "`r`n")
      FileAppend ahk_class %addMe%`n, config.txt

return

;----------------------------------------------------------------
;Quit
;----------------------------------------------------------------
Exit:
ExitApp
This is a basic application, you can accomplish a lot more with autohotkey.
:)
Ответить

Вернуться в «Программирование»