paschalism

NoClose.ahk

May 14th, 2013
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;NoClose.ahk
  2. ; Disable the Close button (X) of selected windows
  3. ; To run, save to BlockInput.ahk and install AutoHotkey from www.autohotkey.com
  4. ;Skrommel @2006
  5.  
  6. #SingleInstance,Force
  7. SetTitleMatchMode,2
  8.  
  9. applicationname=NoClose
  10.  
  11. ids=
  12. oldids=
  13.  
  14. Gosub,INIREAD
  15. Gosub,TRAYMENU
  16. Gosub,STARTUP
  17. OnExit,EXIT
  18. Hotkey,%add%,ADD
  19. Hotkey,%swap%,SWAP
  20.  
  21. Loop
  22. {
  23.   Sleep,500
  24.   allids=
  25.   activeids=
  26.   WinGet,id_,List,,,Program Manager
  27.   Loop,%id_%
  28.   {
  29.     Sleep,0
  30.     id:=id_%A_Index%
  31.     allids=%allids%%id%`,
  32.     IfInString,ids,%id%`,
  33.       activeids=%activeids%%id%`,
  34.     If autodisable=0
  35.       Continue
  36.     IfInString,oldids,%id%`,
  37.       Continue
  38.     WinGetTitle,title,ahk_id %id%
  39.     WinGetClass,class,ahk_id %id%
  40.     rule=%title% ahk_class %class%|||
  41.     IfInString,rules,%rule%
  42.     {
  43.       DISABLE(id)
  44.       activeids=%activeids%%id%`,
  45.     }
  46.   }
  47.   oldids:=allids
  48.   ids:=activeids
  49. }
  50. Return
  51.  
  52.  
  53. STARTUP:
  54. allids=
  55. WinGet,id_,List,,,Program Manager
  56. Loop,%id_%
  57. {
  58.   id:=id_%A_Index%
  59.   allids=%allids%%id%`,
  60.   If disableonstartup=0
  61.     Continue
  62.   WinGetTitle,title,ahk_id %id%
  63.   WinGetClass,class,ahk_id %id%
  64.   rule=%title% ahk_class %class%|||
  65.   IfInString,rules,%rule%
  66.   {
  67.     DISABLE(id)
  68.     ids=%ids%%id%`,
  69.   }
  70. }
  71. oldids:=allids
  72. Return
  73.  
  74.  
  75. EXIT:
  76. If enableonexit=0
  77.   ExitApp
  78. WinGet,id_,List,,,Program Manager
  79. Loop,%id_%
  80. {
  81.   id:=id_%A_Index%
  82.   IfInString,ids,%id%`,
  83.   {
  84.     ENABLE(id)
  85.     StringReplace,ids,ids,%id%`,,
  86.   }
  87. }
  88. ExitApp
  89.  
  90.  
  91. ADD:
  92. WinGet,id,ID,A
  93. WinGetTitle,title,ahk_id %id%
  94. WinGetClass,class,ahk_id %id%
  95. rule=%title% ahk_class %class%|||
  96. IfInString,rules,%rule%
  97.   Return
  98. Else
  99. {
  100.   DISABLE(id)
  101.   rules=%rules%%rule%
  102.   ids=%ids%%id%`,
  103.   IniWrite,%rules%,%applicationname%.ini,Settings,rules
  104. }
  105. Return
  106.  
  107.  
  108. SWAP:
  109. WinGet,id,ID,A
  110. WinGetTitle,title,ahk_id %id%
  111. WinGetClass,class,ahk_id %id%
  112. IfInString,ids,%id%`,
  113. {
  114.   ENABLE(id)
  115.   StringReplace,ids,ids,%id%`,,
  116.   Return
  117. }
  118. DISABLE(id)
  119. ids=%ids%%id%`,
  120. Return
  121.  
  122.  
  123. DISABLE(id) ;By RealityRipple at http://www.xtremevbtalk.com/archive/index.php/t-258725.html
  124. {
  125.   menu:=DllCall("user32\GetSystemMenu","UInt",id,"UInt",0)
  126.   DllCall("user32\DeleteMenu","UInt",menu,"UInt",0xF060,"UInt",0x0)
  127.   WinGetPos,x,y,w,h,ahk_id %id%
  128.   WinMove,ahk_id %id%,,%x%,%y%,%w%,% h-1
  129.   WinMove,ahk_id %id%,,%x%,%y%,%w%,% h+1
  130. }
  131.  
  132.  
  133. ENABLE(id) ;By Mosaic1 at http://www.xtremevbtalk.com/archive/index.php/t-258725.html
  134. {
  135.   menu:=DllCall("user32\GetSystemMenu","UInt",id,"UInt",1)
  136.   DllCall("user32\DrawMenuBar","UInt",id)
  137. }
  138.  
  139.  
  140. TRAYMENU:
  141. Menu,Tray,NoStandard
  142. Menu,Tray,DeleteAll
  143. Menu,Tray,Add,%applicationname%,ABOUT
  144. Menu,Tray,Add,
  145. Menu,Tray,Add,&Settings...,SETTINGS
  146. Menu,Tray,Add,&About...,ABOUT
  147. Menu,Tray,Add,E&xit,EXIT
  148. Menu,Tray,Default,%applicationname%
  149. Menu,Tray,Tip,%applicationname%
  150. Return
  151.  
  152.  
  153. INIREAD:
  154. IfNotExist,%applicationname%.ini
  155. {
  156.   disableonstartup=1
  157.   autodisable=1
  158.   enableonexit=1
  159.   swap=^1
  160.   add=^2
  161.   rules=
  162.   Gosub,INIWRITE
  163.   Gosub,ABOUT
  164. }
  165. IniRead,disableonstartup,%applicationname%.ini,Settings,disableonstartup
  166. IniRead,autodisable,%applicationname%.ini,Settings,autodisable
  167. IniRead,enableonexit,%applicationname%.ini,Settings,enableonexit
  168. IniRead,swap,%applicationname%.ini,Settings,swap
  169. IniRead,add,%applicationname%.ini,Settings,add
  170. IniRead,rules,%applicationname%.ini,Settings,rules
  171. Return
  172.  
  173.  
  174. INIWRITE:
  175. IniWrite,%disableonstartup%,%applicationname%.ini,Settings,disableonstartup
  176. IniWrite,%autodisable%,%applicationname%.ini,Settings,autodisable
  177. IniWrite,%enableonexit%,%applicationname%.ini,Settings,enableonexit
  178. IniWrite,%swap%,%applicationname%.ini,Settings,swap
  179. IniWrite,%add%,%applicationname%.ini,Settings,add
  180. IniWrite,%rules%,%applicationname%.ini,Settings,rules
  181. Return
  182.  
  183.  
  184. SETTINGS:
  185. HotKey,%swap%,Off
  186. HotKey,%add%,Off
  187. Gui,Destroy
  188. Gui,Add,Tab,W340 H330 xm,Options|Rules
  189. Gui,Tab,1
  190. Gui,Add,GroupBox,xm+10 ym+40 w320 h70,&Hotkey to Enable/Disable the active windows' close button
  191. Gui,Add,Hotkey,xp+10 yp+20 w300 vsswap
  192. StringReplace,current,swap,+,Shift +%A_Space%
  193. StringReplace,current,current,^,Ctrl +%A_Space%
  194. StringReplace,current,current,!,Alt +%A_Space%
  195. Gui,Add,Text,xm+20 y+5,Current hotkey: %current%
  196.  
  197. Gui,Add,GroupBox,xm+10 y+30 w320 h70,Hotkey to &Add a new rule
  198. Gui,Add,Hotkey,xm+20 yp+20 w300 vsadd
  199. StringReplace,current,add,+,Shift +%A_Space%
  200. StringReplace,current,current,^,Ctrl +%A_Space%
  201. StringReplace,current,current,!,Alt +%A_Space%
  202. Gui,Add,Text,xm+20 y+5,Current hotkey: %current%
  203.  
  204. Gui,Add,GroupBox,xm+10 y+30 w320 h80,Automatic rule execution
  205. Gui,Add,CheckBox,xm+20 yp+20 Checked%disableonstartup% vsdisableonstartup,Disable close buttons on NoClose &Startup
  206. Gui,Add,CheckBox,xm+20 y+5 Checked%autodisable% vsautodisable,Disable close buttons on &Window Creation
  207. Gui,Add,CheckBox,xm+20 y+5 Checked%enableonexit% vsenableonexit,Enable close buttons on NoClose &Exit
  208.  
  209. Gui,Tab,2
  210. StringReplace,rules,rules,|||,`n,All
  211. Gui,Add,GroupBox,w320 h280 xm+10 y+10,&Windows Titles and Classes
  212. Gui,Add,Edit,xm+20 yp+20 w300 h180 Multi -Wrap vsrules,%rules%
  213. Gui,Add,Text,xm+20 y+5,Syntax: <Part of a Window Title> <ahk_class Class Name>
  214. Gui,Add,Text,xm+20 y+5,Example: Calculator ahk_class SciCalc  
  215. Gui,Add,Text,xm+30 y+5,will disable all Calculator close buttons.
  216. Gui,Add,Text,xm+20 y+5,Either part is optional.
  217.  
  218. Gui,Tab
  219. Gui,Add,Button,xm+10 y+30 w75 GSETTINGSOK,&OK
  220. Gui,Add,Button,x+5 w75 GSETTINGSCANCEL,&Cancel
  221. Gui,Show,,%applicationname% Settings
  222. Return
  223.  
  224. SETTINGSOK:
  225. Gui,Submit
  226. If sswap<>
  227. {
  228.   swap:=sswap
  229.   HotKey,%swap%,SWAP
  230. }
  231. HotKey,%swap%,On
  232. If sadd<>
  233. {
  234.   add:=sadd
  235.   HotKey,%add%,ADD
  236. }
  237. HotKey,%add%,On
  238. If sdelay<>
  239.   delay:=sdelay
  240. StringReplace,rules,srules,`n,|||,All
  241. rules=%rules%|||
  242. Loop
  243. {
  244.   StringReplace,rules,rules,||||||,|||,All
  245.   StringGetPos,pos,rules,||||||
  246.   If pos<0
  247.     Break
  248. }
  249. StringLeft,start,rules,3
  250. If start=|||
  251.   StringTrimLeft,rules,rules,3
  252. disableonstartup:=sdisableonstartup
  253. autodisable:=sautodisable
  254. enableonexit:=senableonexit
  255. Gosub,INIWRITE
  256. Return
  257.  
  258. SETTINGSCANCEL:
  259. HotKey,%swap%,SWAP
  260. HotKey,%swap%,On
  261. HotKey,%add%,ADD
  262. HotKey,%add%,On
  263. Gui,Destroy
  264. Return
  265.  
  266.  
  267. ABOUT:
  268. Gui,99:Destroy
  269. Gui,99:Margin,20,20
  270. Gui,99:Add,Picture,xm Icon1,%applicationname%.exe
  271. Gui,99:Font,Bold
  272. Gui,99:Add,Text,x+10 yp+10,%applicationname% v1.1
  273. Gui,99:Font
  274. Gui,99:Add,Text,y+10,Disable the Close button (X) of selected windows.
  275. Gui,99:Add,Text,y+10,- Press Ctrl+1 to Enable or Disable a close button.
  276. Gui,99:Add,Text,y+5 ,- Press Ctrl+2 to Add a rule.
  277. Gui,99:Add,Text,y+10,- To change the settings, choose Settings in the tray menu.
  278.  
  279. Gui,99:Add,Picture,xm y+20 Icon5,%applicationname%.exe
  280. Gui,99:Font,Bold
  281. Gui,99:Add,Text,x+10 yp+10,1 Hour Software by Skrommel
  282. Gui,99:Font
  283. Gui,99:Add,Text,y+10,For more tools, information and donations, please visit
  284. Gui,99:Font,CBlue Underline
  285. Gui,99:Add,Text,y+5 G1HOURSOFTWARE,www.1HourSoftware.com
  286. Gui,99:Font
  287.  
  288. Gui,99:Add,Picture,xm y+20 Icon7,%applicationname%.exe
  289. Gui,99:Font,Bold
  290. Gui,99:Add,Text,x+10 yp+10,DonationCoder
  291. Gui,99:Font
  292. Gui,99:Add,Text,y+10,Please support the contributors at
  293. Gui,99:Font,CBlue Underline
  294. Gui,99:Add,Text,y+5 GDONATIONCODER,www.DonationCoder.com
  295. Gui,99:Font
  296.  
  297. Gui,99:Add,Picture,xm y+20 Icon6,%applicationname%.exe
  298. Gui,99:Font,Bold
  299. Gui,99:Add,Text,x+10 yp+10,AutoHotkey
  300. Gui,99:Font
  301. Gui,99:Add,Text,y+10,This tool was made using the powerful
  302. Gui,99:Font,CBlue Underline
  303. Gui,99:Add,Text,y+5 GAUTOHOTKEY,www.AutoHotkey.com
  304. Gui,99:Font
  305.  
  306. Gui,99:Show,,%applicationname% About
  307. hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
  308. OnMessage(0x200,"WM_MOUSEMOVE")
  309. Return
  310.  
  311. 1HOURSOFTWARE:
  312.  Run,http://www.1hoursoftware.com,,UseErrorLevel
  313. Return
  314.  
  315. DONATIONCODER:
  316.  Run,http://www.donationcoder.com,,UseErrorLevel
  317. Return
  318.  
  319. AUTOHOTKEY:
  320.  Run,http://www.autohotkey.com,,UseErrorLevel
  321. Return
  322.  
  323. 99GuiClose:
  324.  Gui,99:Destroy
  325.   OnMessage(0x200,"")
  326.   DllCall("DestroyCursor","Uint",hCur)
  327. Return
  328.  
  329. WM_MOUSEMOVE(wParam,lParam)
  330. {
  331.   Global hCurs
  332.   MouseGetPos,,,,ctrl
  333.   If ctrl in Static10,Static14,Static18
  334.     DllCall("SetCursor","UInt",hCurs)
  335.   Return
  336. }
  337. Return
Advertisement
Add Comment
Please, Sign In to add comment