WinCloseAuto() : Closes automatically when specified windows show up

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

WinCloseAuto() : Closes automatically when specified windows show up

17 Jun 2020, 19:48

WinCloseAuto(SetHook, WEP.1, WEP.2, WEP.3, WEP.4)
WinCloseAuto() will monitor and close up to 4 windows.
 
Parameters::
SetHook parameter should not be omitted and should be True to set Hook on, or False to Unhook.
WEP.1 .. WEP.4 are WinExist() parameters which needs to be passed as separate array for each parameter.
Note: WinExist() has 4 parameters. The examples below utilizes only the first parameter

Usage examples:
The following code will auto-close whenever Calculator, Notepad or Windows Task Manager shows up.
 

Code: Select all

#NoEnv
#Warn
#SingleInstance, Force
Process, Priority,,High
#Persistent ; <== required

WinCloseAuto( True, ["ahk_class Notepad"]
                  , ["ahk_class CalcFrame"] 
                  , ["Windows Task Manager ahk_class #32770"] )
 
The following example is similar to above except you can toggle the hook between on and off with the Hotkey. F2
 

Code: Select all

#NoEnv
#Warn
#SingleInstance, Force
Process, Priority,,High
Hook := 0

F2:: WinCloseAuto( Hook:=!Hook, ["ahk_class Notepad"]
                              , ["ahk_class CalcFrame"] 
                              , ["Windows Task Manager ahk_class #32770"] )
 
 
The function:
 

Code: Select all

WinCloseAuto(P*) {        ; WinCloseAuto v0.50 by SKAN on D36I/D36I @ tiny.cc/wincloseauto
Static CBA:=RegisterCallBack("WinCloseAuto"), WEP:="", hHook:=0, EVENT_OBJECT_SHOW:=0x8002
  If IsObject(P)
     Return (P.1=1 && (WEP:=P)) ? hHook:=DllCall("SetWinEventHook","Int",EVENT_OBJECT_SHOW
           ,"Int",EVENT_OBJECT_SHOW, "Ptr",0, "Ptr",CBA, "Int",0, "Int",0, "Int",0, "Ptr")
          : (P.1=0 && (WEP:="")="") ? DllCall("UnhookWinEvent", "Ptr",hHook) : "" 
  If WinExist((WEP.2)*) || WinExist((WEP.3)*)  || WinExist((WEP.4)*) || WinExist((WEP.5)*) 
     PostMessage, 0x112, 0xF060 ;  WM_SYSCOMMAND, SC_CLOSE
}
My Scripts and Functions: V1  V2
Kisang Kim
Posts: 12
Joined: 31 Jul 2019, 02:37

Re: WinCloseAuto() : Closes automatically when specified windows show up

17 Jun 2020, 22:32

wonderfull, thank you.

can i make wantclose.ini and list up like

------ list ini file -----------------------------
ahk_class Notepad
ahk_class CalcFram
Windows Task Manager ahk_class #32770

sorry i'm biginner
need4speed
Posts: 143
Joined: 22 Apr 2016, 06:50

Re: WinCloseAuto() : Closes automatically when specified windows show up

18 Jun 2020, 04:29

thanks for the script.
In my test Closing Win10 calculator (ahk_class Windows.UI.Core.CoreWindow) is not working.

Code: Select all

WinClose, ahk_class WinCloseWindows.UI.Core.CoreWindow
does not work either, do you know why?
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: WinCloseAuto() : Closes automatically when specified windows show up

18 Jun 2020, 05:27

Kisang Kim wrote:
17 Jun 2020, 22:32
wonderfull, thank you.
Welcome.. and welcome to AutoHotkey :)
Kisang Kim wrote:
17 Jun 2020, 22:32
can i make wantclose.ini and list up like

------ list ini file -----------------------------
ahk_class Notepad
ahk_class CalcFram
Windows Task Manager ahk_class #32770

sorry i'm biginner
 
 
wantclose.ini should contain following:

Code: Select all

[WinList]
1=ahk_class Notepad
2=ahk_class CalcFrame
3=Windows Task Manager ahk_class #32770

and should be in the same folder as the following script:

Code: Select all

#NoEnv
#Warn
#SingleInstance, Force
Process, Priority,,High
SetWorkingDir, %A_ScriptDir%
#Persistent

ObjWEP:=[], WinTitle:=""
Loop
{
  IniRead, WinTitle, wantclose.ini, WinList, %A_Index%
  If (WinTitle="ERROR")
     Break
  ObjWEP.Push(StrSplit(WinTitle,",", A_Space))   
} 

WinCloseAuto(True, ObjWEP*)
Return ; // end of auto-execute section


WinCloseAuto(P*) {        ; WinCloseAuto v0.50 by SKAN on D36I/D36I @ tiny.cc/wincloseauto
Static CBA:=RegisterCallBack("WinCloseAuto"), WEP:="", hHook:=0, EVENT_OBJECT_SHOW:=0x8002
  If IsObject(P)
     Return (P.1=1 && (WEP:=P)) ? hHook:=DllCall("SetWinEventHook","Int",EVENT_OBJECT_SHOW
           ,"Int",EVENT_OBJECT_SHOW, "Ptr",0, "Ptr",CBA, "Int",0, "Int",0, "Int",0, "Ptr")
          : (P.1=0 && (WEP:="")="") ? DllCall("UnhookWinEvent", "Ptr",hHook) : "" 
  If WinExist((WEP.2)*) || WinExist((WEP.3)*)  || WinExist((WEP.4)*) || WinExist((WEP.5)*) 
     PostMessage, 0x112, 0xF060 ;  WM_SYSCOMMAND, SC_CLOSE
}
My Scripts and Functions: V1  V2
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: WinCloseAuto() : Closes automatically when specified windows show up

18 Jun 2020, 05:28

need4speed wrote:
18 Jun 2020, 04:29
thanks for the script.
In my test Closing Win10 calculator (ahk_class Windows.UI.Core.CoreWindow) is not working.

Code: Select all

WinClose, ahk_class WinCloseWindows.UI.Core.CoreWindow
does not work either, do you know why?
Ah! Thanks. Didn't test it in Win10. Will do and reply. :)
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: WinCloseAuto() : Closes automatically when specified windows show up

18 Jun 2020, 05:48

need4speed wrote:
18 Jun 2020, 04:29
In my test Closing Win10 calculator (ahk_class Windows.UI.Core.CoreWindow) is not working.
Did a quick test.
AHK Window Spy shows Calculator ahk_class ApplicationFrameWindow for me in Win10 ?!
My Scripts and Functions: V1  V2
need4speed
Posts: 143
Joined: 22 Apr 2016, 06:50

Re: WinCloseAuto() : Closes automatically when specified windows show up

18 Jun 2020, 09:37

AHK Window Spy shows Calculator ahk_class ApplicationFrameWindow for me in Win10 ?!
thanks for checking, you're right. The problem was caused by me when using the WinSpyM Finder Tool,
I accidentally selected the control Windows.UI.Core.CoreWindow not ApplicationFrameWindow.

Win10 flat design is pretty weird, I don't like these hidden borders (5px) left and right.
Netmano
Posts: 58
Joined: 17 Jun 2020, 16:24

Re: WinCloseAuto() : Closes automatically when specified windows show up

20 Jun 2020, 06:27

Awesome script. Incredible that you can so much with few lings of code.
I really need to learn how to wield this power myself, I will reverse engineer your case :D
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: WinCloseAuto() : Closes automatically when specified windows show up

20 Jun 2020, 14:22

@adrian_9832 / @Netmano : Thanks for the feedback :)
My Scripts and Functions: V1  V2
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: WinCloseAuto() : Closes automatically when specified windows show up

13 Jul 2020, 15:10

After 4 weeks observation, I will say the following works fine for dismissing PD ads.

Code: Select all

WinCloseAuto(True, ["Panda Dome ahk_exe PSUAConsole.exe",,,"Panda Dome"])
My Scripts and Functions: V1  V2
User avatar
andymbody
Posts: 927
Joined: 02 Jul 2017, 23:47

Re: WinCloseAuto() : Closes automatically when specified windows show up

02 Mar 2024, 09:18

Thanks @SKAN !

Is there a V2 version of this. I am trying to decipher your compressed function so I can convert, but not successful yet. So I thought I would ask.

Thanks!
Andy

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: windmaya and 68 guests