Close a window whenever it exists

Get help with using AutoHotkey and its commands and hotkeys
DeepMind
Posts: 271
Joined: 19 Jul 2016, 14:47

Close a window whenever it exists

06 Sep 2016, 13:09

i use this script to hide Babylon Window from Alt+Tab thumbnails and generally from Alt+Tab but whenever I start my computer Still There's Babylon window in alt+tab window (my script is running) until I reload the script.

Code: Select all

if WinExist("ahk_exe Babylon.exe")
	WinSet, ExStyle, 0x80, ahk_exe Babylon.exe
User avatar
Grendahl
Posts: 159
Joined: 30 Sep 2013, 08:21

Re: Close a window whenever it exists

06 Sep 2016, 13:14

Most likely your Babylon window is loaded after your script is. From the two lines you show, if babylon.exe isn't there when the script is run, the script can't do anything to it.

You could use WinWait instead of WinExist.
https://autohotkey.com/docs/commands/WinWait.htm
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: Close a window whenever it exists

06 Sep 2016, 14:36

Use SetTimer or Sleep to check for the existence of the window every so often. When I do things like monitor the active window I find that anything faster than 4 times per second starts to eat CPU to no good purpose. I notice AHK uses 250 ms for the default for some of its window timings so perhaps that is inherent in windows. But experiment with the sleep/timer delay values to get a feel for it.
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: Close a window whenever it exists

06 Sep 2016, 21:53

In my opinion using set timer for this is a bad idea.

1st it interfers with other scripts running
2nd it eats up unnecessary CPU time

i would use the onmessage shellhooks method


exameple

Code: Select all

Gui +LastFound
Var_hWnd := WinExist()
DllCall("RegisterShellHookWindow", UInt, Var_hWnd)
Var_MsgNum := DllCall("RegisterWindowMessage", Str,"SHELLHOOK")
OnMessage(Var_MsgNum, "MainCode")
Return 



MainCode( wParam,lParam )
{
If (wParam = 1) 
	{
	WinGetTitle, Title, ahk_id %lParam%
	If   Title = "babylon"
		{
		WinClose, ahk_id %lParam% 
		}
	}
}
Whenever a windows i created it will run the main code function. you might need to adjust it if you want to do it by .exe name.

it reacts far faster then a settimer with 500ms wait
and use far less resources
DeepMind
Posts: 271
Joined: 19 Jul 2016, 14:47

Re: Close a window whenever it exists

07 Sep 2016, 00:33

SvenBent wrote:In my opinion using set timer for this is a bad idea.

1st it interfers with other scripts running
2nd it eats up unnecessary CPU time

i would use the onmessage shellhooks method


exameple

Code: Select all

Gui +LastFound
Var_hWnd := WinExist()
DllCall("RegisterShellHookWindow", UInt, Var_hWnd)
Var_MsgNum := DllCall("RegisterWindowMessage", Str,"SHELLHOOK")
OnMessage(Var_MsgNum, "MainCode")
Return 



MainCode( wParam,lParam )
{
If (wParam = 1) 
	{
	WinGetTitle, Title, ahk_id %lParam%
	If   Title = "babylon"
	
		{
		WinClose, ahk_id %lParam% 
		}
	}
}
Whenever a windows i created it will run the main code function. you might need to adjust it if you want to do it by .exe name.

it reacts far faster then a settimer with 500ms wait
and use far less resources
tnx I'll try it :)

Return to “Ask For Help”

Who is online

Users browsing this forum: aseiot, Bing [Bot], flyingDman, nacken012 and 157 guests