NoClose屏蔽窗口关闭按钮并屏蔽Alt+F4关窗快捷键

 

  NoClose屏蔽窗口关闭按钮并屏蔽Alt+F4关窗快捷键

 

NoClose屏蔽窗口关闭按钮并屏蔽Alt+F4关窗快捷键

 

; 禁用关闭窗口的快捷键Alt+F4
!F4::return

 

; 按快捷键 Ctrl + 1 屏蔽当前窗口的关闭按钮,禁止随意关窗

;NoClose.ahk
; Disable the Close button (X) of selected windows
; To run, save to BlockInput.ahk and install AutoHotkey from www.AUTOHOTKEY.com
;Skrommel @2006

#SingleInstance,Force
SetTitleMatchMode,2

applicationname=NoClose

ids=
oldids=

gosub,INIREAD
gosub,TRAYMENU
gosub,STARTUP
OnExit,Exit
Hotkey,%ADD%,ADD
Hotkey,%SWAP%,SWAP

loop
{
	Sleep,500
	allids=
	activeids=
	WinGet,id_,List,,,Program Manager
	loop,%id_%
	{
		Sleep,0
		id:=id_%A_Index%
		allids=%allids%%id%`,
		IfInString,ids,%id%`,
			activeids=%activeids%%id%`,
		if autodisable=0
			continue
		IfInString,oldids,%id%`,
			continue
		WinGetTitle,title,ahk_id %id%
		WinGetClass,class,ahk_id %id%
		rule=%title% ahk_class %class%|||
		IfInString,rules,%rule%
		{
			DISABLE(id)
			activeids=%activeids%%id%`,
		}
	}
	oldids:=allids
	ids:=activeids
}
return


STARTUP:
	allids=
	WinGet,id_,List,,,Program Manager
	loop,%id_%
	{
		id:=id_%A_Index%
		allids=%allids%%id%`,
		if disableonstartup=0
			continue
		WinGetTitle,title,ahk_id %id%
		WinGetClass,class,ahk_id %id%
		rule=%title% ahk_class %class%|||
		IfInString,rules,%rule%
		{
			DISABLE(id)
			ids=%ids%%id%`,
		}
	}
	oldids:=allids
return


EXIT:
	if enableonexit=0
		ExitApp
	WinGet,id_,List,,,Program Manager
	loop,%id_%
	{
		id:=id_%A_Index%
		IfInString,ids,%id%`,
		{
			ENABLE(id)
			StringReplace,ids,ids,%id%`,,
		}
	}
	ExitApp


ADD:
	WinGet,id,ID,A
	WinGetTitle,title,ahk_id %id%
	WinGetClass,class,ahk_id %id%
	rule=%title% ahk_class %class%|||
	IfInString,rules,%rule%
		return
	else
	{
		DISABLE(id)
		rules=%rules%%rule%
		ids=%ids%%id%`,
		IniWrite,%rules%,%applicationname%.ini,Settings,rules
	}
return


SWAP:
	WinGet,id,ID,A
	WinGetTitle,title,ahk_id %id%
	WinGetClass,class,ahk_id %id%
	IfInString,ids,%id%`,
	{
		ENABLE(id)
		StringReplace,ids,ids,%id%`,,
		return
	}
	DISABLE(id)
	ids=%ids%%id%`,
return


DISABLE(id) ;By RealityRipple at http://www.xtremevbtalk.com/archive/index.php/t-258725.html
{
	Menu:=DllCall("user32\GetSystemMenu","UInt",id,"UInt",0)
	DllCall("user32\DeleteMenu","UInt",Menu,"UInt",0xF060,"UInt",0x0)
	WinGetPos,x,y,w,h,ahk_id %id%
	WinMove,ahk_id %id%,,%x%,%y%,%w%,% h-1
	WinMove,ahk_id %id%,,%x%,%y%,%w%,% h+1
}


ENABLE(id) ;By Mosaic1 at http://www.xtremevbtalk.com/archive/index.php/t-258725.html
{
	Menu:=DllCall("user32\GetSystemMenu","UInt",id,"UInt",1)
	DllCall("user32\DrawMenuBar","UInt",id)
}


TRAYMENU:
	Menu,Tray,NoStandard
	Menu,Tray,DeleteAll
	Menu,Tray,ADD,%applicationname%,ABOUT
	Menu,Tray,ADD,
	Menu,Tray,ADD,&SETTINGS...,SETTINGS
	Menu,Tray,ADD,&ABOUT...,ABOUT
	Menu,Tray,ADD,E&xit,EXIT
	Menu,Tray,default,%applicationname%
	Menu,Tray,Tip,%applicationname%
return


INIREAD:
	IfNotExist,%applicationname%.ini
	{
		disableonstartup=1
		autodisable=1
		enableonexit=1
		swap=^1
		add=^2
		rules=
		gosub,INIWRITE
		gosub,ABOUT
	}
	IniRead,disableonstartup,%applicationname%.ini,Settings,disableonstartup
	IniRead,autodisable,%applicationname%.ini,Settings,autodisable
	IniRead,enableonexit,%applicationname%.ini,Settings,enableonexit
	IniRead,swap,%applicationname%.ini,Settings,swap
	IniRead,add,%applicationname%.ini,Settings,add
	IniRead,rules,%applicationname%.ini,Settings,rules
return


INIWRITE:
	IniWrite,%disableonstartup%,%applicationname%.ini,Settings,disableonstartup
	IniWrite,%autodisable%,%applicationname%.ini,Settings,autodisable
	IniWrite,%enableonexit%,%applicationname%.ini,Settings,enableonexit
	IniWrite,%swap%,%applicationname%.ini,Settings,swap
	IniWrite,%add%,%applicationname%.ini,Settings,add
	IniWrite,%rules%,%applicationname%.ini,Settings,rules
return


SETTINGS:
	Hotkey,%SWAP%,Off
	Hotkey,%ADD%,Off
	Gui,Destroy
	Gui,Add,Tab,W340 H330 xm,Options|Rules
		Gui,Tab,1
			Gui,Add,GroupBox,xm+10 ym+40 w320 h70,&Hotkey to Enable/Disable the active windows' close button
			Gui,Add,Hotkey,xp+10 yp+20 w300 vsswap
			StringReplace,current,swap,+,Shift +%A_Space%
			StringReplace,current,current,^,Ctrl +%A_Space%
			StringReplace,current,current,!,Alt +%A_Space%
			Gui,Add,Text,xm+20 y+5,Current Hotkey: %current%

			Gui,Add,GroupBox,xm+10 y+30 w320 h70,Hotkey to &ADD a new rule
			Gui,Add,Hotkey,xm+20 yp+20 w300 vsadd
			StringReplace,current,add,+,Shift +%A_Space%
			StringReplace,current,current,^,Ctrl +%A_Space%
			StringReplace,current,current,!,Alt +%A_Space%
			Gui,Add,Text,xm+20 y+5,Current Hotkey: %current%

			Gui,Add,GroupBox,xm+10 y+30 w320 h80,Automatic rule execution
			Gui,Add,CheckBox,xm+20 yp+20 Checked%disableonstartup% vsdisableonstartup,Disable close buttons on NoClose &Startup
			Gui,Add,CheckBox,xm+20 y+5 Checked%autodisable% vsautodisable,Disable close buttons on &Window Creation
			Gui,Add,CheckBox,xm+20 y+5 Checked%enableonexit% vsenableonexit,Enable close buttons on NoClose &Exit

		Gui,Tab,2
			StringReplace,rules,rules,|||,`n,All
			Gui,Add,GroupBox,w320 h280 xm+10 y+10,&Windows Titles and Classes
			Gui,Add,Edit,xm+20 yp+20 w300 h180 Multi -Wrap vsrules,%rules%
			Gui,Add,Text,xm+20 y+5,Syntax: <Part of a Window Title> <ahk_class class Name>
			Gui,Add,Text,xm+20 y+5,Example: Calculator ahk_class SciCalc
			Gui,Add,Text,xm+30 y+5,will disable all Calculator close buttons.
			Gui,Add,Text,xm+20 y+5,Either part is optional.

	Gui,Tab
	Gui,Add,Button,xm+10 y+30 w75 GSETTINGSOK,&OK
	Gui,Add,Button,x+5 w75 GSETTINGSCANCEL,&Cancel
	Gui,Show,,%applicationname% Settings
return

SETTINGSOK:
	Gui,Submit
	if sswap<>
	{
		swap:=sswap
		Hotkey,%SWAP%,SWAP
	}
	Hotkey,%SWAP%,On
	if sadd<>
	{
		add:=sadd
		Hotkey,%ADD%,ADD
	}
	Hotkey,%ADD%,On
	if sdelay<>
		delay:=sdelay
	StringReplace,rules,srules,`n,|||,All
	rules=%rules%|||
	loop
	{
		StringReplace,rules,rules,||||||,|||,All
		StringGetPos,pos,rules,||||||
		if pos<0
			break
	}
	StringLeft,start,rules,3
	if start=|||
		StringTrimLeft,rules,rules,3
	disableonstartup:=sdisableonstartup
	autodisable:=sautodisable
	enableonexit:=senableonexit
	gosub,INIWRITE
return

SETTINGSCANCEL:
	Hotkey,%SWAP%,SWAP
	Hotkey,%SWAP%,On
	Hotkey,%ADD%,ADD
	Hotkey,%ADD%,On
	Gui,Destroy
return


ABOUT:
	Gui,99:Destroy
	Gui,99:Margin,20,20
	Gui,99:Add,Picture,xm Icon1,%applicationname%.exe
	Gui,99:Font,Bold
	Gui,99:Add,Text,x+10 yp+10,%applicationname% v1.1
	Gui,99:Font
	Gui,99:Add,Text,y+10,Disable the Close button (X) of selected windows.
	Gui,99:Add,Text,y+10,- Press Ctrl+1 to Enable or Disable a close button.
	Gui,99:Add,Text,y+5 ,- Press Ctrl+2 to Add a rule.
	Gui,99:Add,Text,y+10,- To change the settings, choose Settings in the tray Menu.

	Gui,99:Add,Picture,xm y+20 Icon5,%applicationname%.exe
	Gui,99:Font,Bold
	Gui,99:Add,Text,x+10 yp+10,1 Hour Software by Skrommel
	Gui,99:Font
	Gui,99:Add,Text,y+10,For more tools, information and donations, please visit
	Gui,99:Font,CBlue Underline
	Gui,99:Add,Text,y+5 G1HOURSOFTWARE,www.1HourSoftware.com
	Gui,99:Font

	Gui,99:Add,Picture,xm y+20 Icon7,%applicationname%.exe
	Gui,99:Font,Bold
	Gui,99:Add,Text,x+10 yp+10,DonationCoder
	Gui,99:Font
	Gui,99:Add,Text,y+10,Please support the contributors at
	Gui,99:Font,CBlue Underline
	Gui,99:Add,Text,y+5 GDONATIONCODER,www.DonationCoder.com
	Gui,99:Font

	Gui,99:Add,Picture,xm y+20 Icon6,%applicationname%.exe
	Gui,99:Font,Bold
	Gui,99:Add,Text,x+10 yp+10,AutoHotkey
	Gui,99:Font
	Gui,99:Add,Text,y+10,This tool was made using the powerful
	Gui,99:Font,CBlue Underline
	Gui,99:Add,Text,y+5 GAUTOHOTKEY,www.AUTOHOTKEY.com
	Gui,99:Font

	Gui,99:Show,,%applicationname% About
	hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
	OnMessage(0x200,"WM_MOUSEMOVE")
return

1HOURSOFTWARE:
	Run,http://www.1hoursoftware.com,,UseErrorLevel
return

DONATIONCODER:
	Run,http://www.donationcoder.com,,UseErrorLevel
return

AUTOHOTKEY:
	Run,http://www.autohotkey.com,,UseErrorLevel
return

99GuiClose:
	Gui,99:Destroy
	OnMessage(0x200,"")
	DllCall("DestroyCursor","Uint",hCur)
return

WM_MOUSEMOVE(wParam,lParam)
{
	global hCurs
	MouseGetPos,,,,ctrl
	if ctrl in Static10,Static14,Static18
		DllCall("SetCursor","UInt",hCurs)
	return
}
return

 

; 按快捷键 Win+Z 保持计算器一直运行,不关闭

#SingleInstance,Force
SetTitleMatchMode,2

#z:: ;~Win+Z
	; Run Notepad
	Run Calc
	SetTimer,CheckLoop,500
return

CheckLoop:
	{
		; Process,WaitClose,Notepad.exe,5
		; if %ErrorLevel% =0
		Process,Exist,Calc.exe
		if %ErrorLevel% =0
		{
			Sleep,100
			IfWinNotExist,计算器
			{
				Sleep,100
				IfWinNotExist,计算器
				{
					Sleep,100
					IfWinNotExist,计算器
					{
						Sleep,100
						IfWinNotExist,计算器
						{
							Sleep,100
							IfWinNotExist,计算器
							{
								Run Calc
								; SetTimer,CheckLoop,Off
							}
						}
					}
				}
			}
		}
	}

 

NoClose屏蔽窗口关闭按钮并屏蔽Alt+F4关窗快捷键

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA捐赠
共{{data.count}}人
人已捐赠
其他

输入法控制相关示例合集

2025-4-23 11:01:10

其他

影子输入法小技巧之tsf问题排查

2022-9-10 10:07:08

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
有新私信 私信列表
搜索