paschalism

GoneIn60s.ahk

May 14th, 2013
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;GoneIn60s.ahk
  2. ; Recover closed applications
  3. ;Skrommel @ 2006
  4.  
  5. #NoEnv
  6. #SingleInstance,Force
  7.  
  8. OnExit,EXIT
  9.  
  10. CoordMode,Mouse,Screen
  11. CoordMode,ToolTip,Screen
  12.  
  13. SysGet,SM_CYCAPTION,4
  14. SysGet,SM_CXBORDER,5
  15. SysGet,SM_CYBORDER,6
  16. SysGet,SM_CXEDGE,45
  17. SysGet,SM_CYEDGE,46
  18. SysGet,SM_CXFIXEDFRAME,7
  19. SysGet,SM_CYFIXEDFRAME,8
  20. SysGet,SM_CXSIZEFRAME,32
  21. SysGet,SM_CYSIZEFRAME,33
  22. SysGet,SM_CXSIZE,30
  23. SysGet,SM_CYSIZE,31
  24.  
  25. applicationname=GoneIn60s
  26.  
  27. Gosub,INIREAD
  28.  
  29. inside=0
  30.  
  31. Gosub,TRAYMENU
  32. SetTimer,CHECK,1000
  33.  
  34. Loop
  35. {
  36.   Sleep,100
  37.   MouseGetPos,mx,my,win1
  38.   parent:=DllCall("GetParent","uint",win1)
  39.   If parent>0
  40.     Continue
  41.   WinGetPos,x,y,w,h,ahk_id %win1%
  42.   l:=x+w-SM_CXSIZEFRAME-SM_CXSIZE
  43.   t:=y+SM_CYSIZEFRAME
  44.   r:=x+w-SM_CXSIZEFRAME
  45.   b:=y+SM_CYSIZEFRAME+SM_CYSIZE
  46.   If (mx<l Or mx>r Or my<t Or my>b)
  47.   {
  48.     If inside=1
  49.     {
  50.       ToolTip,
  51.       Hotkey,LButton,CLICK,Off
  52.       inside=0
  53.     }
  54.   }
  55.   Else
  56.   {
  57.     If inside=0
  58.     {
  59.       WinGet,program,ProcessName,ahk_id %win1%
  60.       If program In %ignore%
  61.         Continue
  62.       WinGetClass,class,ahk_id %win1%
  63.       If class In %nonwindows%
  64.         Continue
  65.       ToolTip,Gone in %timeout% seconds
  66.       Hotkey,LButton,CLICK,On
  67.       inside=1
  68.     }
  69.   }
  70. }
  71.  
  72.  
  73. !F4::
  74. WinGet,win1,Id,A
  75. parent:=DllCall("GetParent",UInt,win1)
  76. If parent>0
  77.   Return
  78. WinGetClass,class,ahk_id %win1%
  79. If class In %nonwindows%
  80.   Return
  81.  
  82. CLICK:
  83. WinHide,ahk_id %win1%
  84. IfNotInString,closing,%win1%
  85. {
  86.   closing=%closing%%win1%-%A_TickCount%|
  87.   Gosub,TRAYMENU
  88. }
  89. Return
  90.  
  91.  
  92. CHECK:
  93. StringSplit,part_,closing,|
  94. Loop,% part_0-1
  95. {
  96.   StringSplit,info_,part_%A_Index%,-
  97.   IfWinExist,ahk_id %info_1%
  98.   {
  99.     left:=Ceil((info_2+timeout*1000-A_TickCount)/1000)
  100.     TrayTip,%applicationname%,Recovered with %left% seconds left!
  101.     StringReplace,closing,closing,%info_1%-%info_2%|
  102.     Gosub,TRAYMENU
  103.   }
  104.   Else
  105.   If (A_TickCount>=info_2+timeout*1000)
  106.   {
  107.     DetectHiddenWindows,On
  108.     If kill=1
  109.     {
  110.       WinGet,pid,Pid,ahk_id %info_1%
  111.       Process,Close,%pid%
  112.     }
  113.     Else
  114.       WinClose,ahk_id %info_1%
  115.     DetectHiddenWindows,Off
  116.     Sleep,1000
  117.     WinShow,ahk_id %info_1%
  118.     StringReplace,closing,closing,%info_1%-%info_2%|
  119.     Gosub,TRAYMENU
  120.   }
  121.  }
  122. Return
  123.  
  124.  
  125. RECOVER:
  126. menuitem:=A_ThisMenuItemPos-4
  127. StringSplit,part_,closing,|
  128. StringSplit,info_,part_%menuitem%,-
  129. WinShow,ahk_id %info_1%
  130. Return
  131.  
  132.  
  133. RECOVERALL:
  134. StringSplit,part_,closing,|
  135. Loop,% part_0-1
  136. {
  137.   StringSplit,info_,part_%A_Index%,-
  138.   WinShow,ahk_id %info_1%
  139. }
  140. Return
  141.  
  142.  
  143. CLOSEALL:
  144. StringSplit,part_,closing,|
  145. Loop,% part_0-1
  146. {
  147.   StringSplit,info_,part_%A_Index%,-
  148.   DetectHiddenWindows,On
  149.   If kill=1
  150.   {
  151.     WinGet,pid,Pid,ahk_id %info_1%
  152.     Process,Close,%pid%
  153.   }
  154.   Else
  155.     WinClose,ahk_id %info_1%
  156.   DetectHiddenWindows,Off
  157.   Sleep,1000
  158.   WinShow,ahk_id %info_1%
  159.   StringReplace,closing,closing,%info_1%-%info_2%|
  160.   Gosub,TRAYMENU
  161.  }
  162. Return
  163.  
  164.  
  165.  
  166. SETTINGS:
  167. ok=0
  168. Gui,Destroy
  169. Gui,Margin,20,10
  170.  
  171. Gui,Add,GroupBox,xm-10 w300 h50,&Time to wait
  172. Gui,Add,Edit,xm yp+20 w100 vtimeout
  173. Gui,Add,UpDown,x+5,%timeout%
  174. Gui,Add,Text,x+5 yp+2,seconds
  175.  
  176. Gui,Add,GroupBox,xm-10 y+20 w300 h50,Actions
  177. Gui,Add,CheckBox,xm yp+20 vkill Checked%kill%,&Kill windows   Won't ask to save changed documents!
  178.  
  179. Gui,Add,GroupBox,xm-10 y+20 w300 h120,&Programs to ignore
  180. Gui,Add,Edit,xm yp+20 r5 w280 vignore,%ignore%
  181. Gui,Add,Text,xm y+5,Example: Notepad.exe,Calc.exe,Pbrush.exe
  182.  
  183. Gui,Add,GroupBox,xm-10 y+20 w300 h120,Cl&asses to ignore
  184. Gui,Add,Edit,xm yp+20 r5 w280 vsystem,%system%
  185. Gui,Add,Text,xm y+5,Example: Shell_TrayWnd,Progman,#32768
  186.  
  187. Gui,Add,Button,xm y+20 w75 gSETTINGSOK,&OK
  188. Gui,Add,Button,x+5 w75 gSETTINGSCANCEL,&Cancel
  189.  
  190. Gui,Show,,%applicationname% Settings
  191.  
  192. Loop
  193. {
  194.   If ok=1
  195.     Break
  196.   MouseGetPos,x,y,winid,ctrlid
  197.   WinGet,program,ProcessName,ahk_id %winid%
  198.   WinGetClass,class,ahk_id %winid%
  199.   ToolTip,Program: %program%`nClass:     %class%
  200.   Sleep,100
  201. }
  202. ToolTip,
  203. Return
  204.  
  205.  
  206. GuiClose:
  207. SETTINGSOK:
  208. ok=1
  209. Gui,Submit
  210. Gosub,INIWRITE
  211. Return
  212.  
  213.  
  214. SETTINGSCANCEL:
  215. ok=1
  216. Gui,Destroy
  217. Return
  218.  
  219.  
  220. TRAYMENU:
  221. Menu,Tray,NoStandard
  222. Menu,Tray,DeleteAll
  223. Menu,Tray,Add,%applicationname%,RECOVERALL
  224. Menu,Tray,Add
  225. Menu,Tray,Add,&Recover All,RECOVERALL
  226. Menu,Tray,Add
  227. DetectHiddenWindows,On
  228. StringSplit,part_,closing,|
  229. Loop,% part_0-1
  230. {
  231.   StringSplit,info_,part_%A_Index%,-
  232.   WinGetTitle,title,ahk_id %info_1%
  233.   Menu,Tray,Add,&%A_Index% - %title%,RECOVER
  234. }
  235. DetectHiddenWindows,Off
  236. Menu,Tray,Add
  237. Menu,Tray,Add,&Settings...,SETTINGS
  238. Menu,Tray,Add,&About...,ABOUT
  239. Menu,Tray,Add,E&xit,EXIT
  240. Menu,Tray,Default,%applicationname%
  241. Menu,Tray,Tip,%applicationname%
  242. Return
  243.  
  244.  
  245. ABOUT:
  246. ok=1
  247. Gui,99:Destroy
  248. Gui,99:Margin,20,20
  249. Gui,99:Add,Picture,xm Icon1,%applicationname%.exe
  250. Gui,99:Font,Bold
  251. Gui,99:Add,Text,x+10 yp+10,%applicationname% v1.4
  252. Gui,99:Font
  253. Gui,99:Add,Text,y+10,Recover closed applications
  254. Gui,99:Add,Text,y+10,- To recover, rightclick the tray icon and choose an application
  255. Gui,99:Add,Text,y+10,- Doubleclick the tray icon to recover all closed applications
  256. Gui,99:Add,Text,y+10,- If not recovered, it is gone in %timeout% seconds
  257.  
  258. Gui,99:Add,Picture,xm y+20 Icon5,%applicationname%.exe
  259. Gui,99:Font,Bold
  260. Gui,99:Add,Text,x+10 yp+10,1 Hour Software by Skrommel
  261. Gui,99:Font
  262. Gui,99:Add,Text,y+10,For more tools, information and donations, please visit
  263. Gui,99:Font,CBlue Underline
  264. Gui,99:Add,Text,y+5 G1HOURSOFTWARE,www.1HourSoftware.com
  265. Gui,99:Font
  266.  
  267. Gui,99:Add,Picture,xm y+20 Icon7,%applicationname%.exe
  268. Gui,99:Font,Bold
  269. Gui,99:Add,Text,x+10 yp+10,DonationCoder
  270. Gui,99:Font
  271. Gui,99:Add,Text,y+10,Please support the contributors at
  272. Gui,99:Font,CBlue Underline
  273. Gui,99:Add,Text,y+5 GDONATIONCODER,www.DonationCoder.com
  274. Gui,99:Font
  275.  
  276. Gui,99:Add,Picture,xm y+20 Icon6,%applicationname%.exe
  277. Gui,99:Font,Bold
  278. Gui,99:Add,Text,x+10 yp+10,AutoHotkey
  279. Gui,99:Font
  280. Gui,99:Add,Text,y+10,This tool was made using the powerful
  281. Gui,99:Font,CBlue Underline
  282. Gui,99:Add,Text,y+5 GAUTOHOTKEY,www.AutoHotkey.com
  283. Gui,99:Font
  284.  
  285. Gui,99:Show,,%applicationname% About
  286. hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
  287. OnMessage(0x200,"WM_MOUSEMOVE")
  288. Return
  289.  
  290. 1HOURSOFTWARE:
  291.  Run,http://www.1hoursoftware.com,,UseErrorLevel
  292. Return
  293.  
  294. DONATIONCODER:
  295.  Run,http://www.donationcoder.com,,UseErrorLevel
  296. Return
  297.  
  298. AUTOHOTKEY:
  299.  Run,http://www.autohotkey.com,,UseErrorLevel
  300. Return
  301.  
  302. 99GuiClose:
  303.  Gui,99:Destroy
  304.   OnMessage(0x200,"")
  305.   DllCall("DestroyCursor","Uint",hCur)
  306. Return
  307.  
  308. WM_MOUSEMOVE(wParam,lParam)
  309. {
  310.   Global hCurs
  311.   MouseGetPos,,,,ctrl
  312.   If ctrl in Static10,Static14,Static18
  313.     DllCall("SetCursor","UInt",hCurs)
  314.   Return
  315. }
  316. Return
  317.  
  318.  
  319. EXIT:
  320. Gosub,CLOSEALL
  321. ExitApp
  322.  
  323.  
  324. INIREAD:
  325. IniRead,timeout,%applicationname%.ini,Settings,timeout
  326. If timeout=ERROR
  327.   timeout=60
  328. IniRead,kill,%applicationname%.ini,Settings,kill
  329. If kill=ERROR
  330.   kill=0
  331. IniRead,ignore,%applicationname%.ini,Settings,ignore
  332. If ignore=ERROR
  333.   ignore=Notepad.exe
  334. IniRead,system,%applicationname%.ini,Settings,system
  335. If system=ERROR
  336.   system=Shell_TrayWnd,Progman,#32768,Basebar,DV2ControlHost
  337. StringReplace,ignore,ignore,%A_Space%`,,`,,All
  338. StringReplace,ignore,ignore,`,%A_Space%,`,,All
  339. StringReplace,system,system,%A_Space%`,,`,,All
  340. StringReplace,system,system,`,%A_Space%,`,,All
  341. Return
  342.  
  343.  
  344. INIWRITE:
  345. StringReplace,ignore,ignore,%A_Space%`,,`,,All
  346. StringReplace,ignore,ignore,`,%A_Space%,`,,All
  347. StringReplace,system,system,%A_Space%`,,`,,All
  348. StringReplace,system,system,`,%A_Space%,`,,All
  349. IniWrite,%timeout%,%applicationname%.ini,Settings,timeout
  350. IniWrite,%kill%,%applicationname%.ini,Settings,kill
  351. IniWrite,%ignore%,%applicationname%.ini,Settings,ignore
  352. IniWrite,%system%,%applicationname%.ini,Settings,system
  353. Return
Advertisement
Add Comment
Please, Sign In to add comment