Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Auto Hide Windows to Screen Edge w/ MouseOver


  • Please log in to reply
19 replies to this topic
berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009
Hey guys,
So I rewrote this code I wrote in a very professional manner.

Posted Image

#SingleInstance Force

if IsLabel("PreferenceSettings") = 0
{
	msgbox , , Welcome!, Hello! I hope you enjoy this script!`n`nWhat it does: press the hotkey to turn on auto-hiding for the active window. The window will hide when the cursor is not over the window. It will return when you move the cursor to a predefined area on the edge of the screen.  Hide as many windows as you want, and press the hotkey again with a window selected to turn auto-hiding off.`n`nNote: you must run this setup wizard as a .ahk file and not as a .exe file.
	inputbox, MouseoverWidth, Welcome!, To start`, please enter the size in pixels of the predefined mouseover area. This box is 300x200 pixels. Suggested - 200,,300,200,,,,,200
	if ErrorLevel <> 0
		exitapp
	loop
	{
		inputbox, UserHotkey, Welcome!, Please type the hotkey you would like to use in AutoHotkey format:`nCTRL = ^`nWindows = #`nAlt = !`nShift = +`nTo see more`, type help.,,300,250,,,,,#j
		if ErrorLevel <> 0
			exitapp
		If (UserHotkey = "help") or (UserHotkey = "Help")
		{
			run "http://www.autohotkey.com/docs/KeyList.htm"
			continue
		}
		break
	}
	inputbox, UserUnhideHotkey, Welcome!, Please type a hotkey to unhide all hidden windows. Suggested - SHIFT + Previously defined hotkey,,300,200,,,,,+%UserHotkey%
	if ErrorLevel <> 0
		exitapp
	inputbox, UserSnapHotkey, Welcome!, Please type a hotkey to snap the window to the closest screen corner.,,300,200,,,,,+#.
	if ErrorLevel <> 0
		exitapp
	Msgbox 4, Welcome!, Would you like to use graphical elements?
	if ErrorLevel <> 0
		exitapp
	IfMsgBox No
		gfx := 0
	else {
		gfx := 1
		loop
		{
			inputbox, HideColor, Welcome!, Please enter a color that will indicate auto-hiding has been turned on`, in hexadecimal format. Suggested - Green (00FF00)`n`nFor help with hexadecimal colors`, type help.,,300,200,,,,,00FF00
			if ErrorLevel <> 0
			{
				gfx := 0
				break
			}
			If (Hidecolor = "help") or (Hidecolor = "Help")
			{
				run "http://www.autohotkey.com/docs/commands/Progress.htm#colors"
				continue
			}
			break
		}
		inputbox, UnhideColor, Welcome!, Please enter a color that will indicate auto-hiding has been turned off`, in hexadecimal format. Suggested - Red (FF0000),,300,200,,,,,FF0000
		if ErrorLevel <> 0
			gfx := 0
		inputbox, MinimizeColor, Welcome!, Please enter a color that will appear when a window auto-hides`, in hexadecimal format. Suggested - Blue (0000FF),,300,200,,,,,0000FF
		if ErrorLevel <> 0
			gfx := 0
		inputbox, GUIThickness, Welcome!, Please enter the desired width in pixels of the graphical elements.  A higher number will lead to more conspicuous graphics. Suggested - 8,,300,200,,,,,8
		if ErrorLevel <> 0
			gfx := 0
	}
	Msgbox 4, Welcome!, Would you like to set up some programs to be auto-hidden on default?
	if ErrorLevel <> 0
		exitapp
	n := 0
	IfMsgBox Yes
	{
		loop
		{
			inputbox, FilePath, Welcome!, Please enter the path (e.g. C:\My Documents\My File.extension or http://www.website.com/) of a%nother% window you would like to have open at startup`, then wait for the program to load. Press cancel to skip this step.,,400,200
			if ErrorLevel <> 0
				break
			run, %FilePath%, , UseErrorLevel
			if ErrorLevel
			{
				Msgbox, , Welcome!, Invalid filepath. Please try again.
				continue
			}
			sleep 2000
			wingettitle, ActiveTitle, A
			Msgbox 4, Welcome!, %ActiveTitle%`n`nIs this correct?
			IfMsgBox No
				Continue
			Winget, NewHWND, ID, %ActiveTitle%
			wingetpos, x, y, Width, Height, ahk_id %NewHWND%
			Msgbox, , Welcome!, Please position and size the window the way you would like it to appear by default`, then press OK when you are finished.
			wingetpos, x, y, Width, Height, ahk_id %NewHWND%
			loop
			{
				inputbox, Commands, Welcome!, Would you like to send any commands to this window when it opens? E.g. CTRL + END to go to the end of a document.`n`nYou must enter them in AutoHotkey format`, for example ^{end}. For help type help.`n`nTo skip this step press cancel.,,400,250
				if (Commands = "help") or (Commands = "Help")
				{
					Commands =
					run, http://www.autohotkey.com/docs/commands/Send.htm
					continue
				}
				break
			}
			Msgbox 4, Welcome!, Save this configuration?
			IfMsgBox Yes
			{
				n++
				winclose ahk_id %NewHWND%
				min := 10000
				if (x < min)
					min := x, ScreenEdge := "Left"
				if (y < min)
					min := y, ScreenEdge := "Top"
				if ((A_ScreenWidth - 1 - x - Width) < min)
					min := A_ScreenWidth - 1 - x - Width, ScreenEdge := "Right"
				if ((A_ScreenHeight - 1 - y - Height) < min)
					ScreenEdge := "Bottom"
WindowsOnStartUp =
(
%WindowsOnStartUp%run, %FilePath%
winwaitactive %ActiveTitle%
Winget, NewHWND, ID, %ActiveTitle%
Winmove, ahk_id `%NewHWND`%, , %x%, %y%, %Width%, %Height%
HWND%n% := NewHWND
Active%n% := 1
Screenedge%n% = %ScreenEdge%

)
				if Commands
					WindowsOnStartUp = %WindowsOnStartUp%sleep 1000`nsend %Commands%`n
				if (nother = "nother")
					s = s
				nother = nother
				continue
			}
		}
	Msgbox, , Welcome!, You have configured %n% window%s% to run on startup.
	}
	Msgbox 518, Welcome!, All set! The script will now close and re-open with your saved preferences.`n`nTo edit these preferences at any time`, you can edit the .ahk file and scroll to the bottom to find the PreferenceSettings label.  You can edit these manually`, or delete the entire section and restart the script to reengage the wizard.
	IfMsgBox Cancel
		Exitapp
	IfMsgBox TryAgain
		reload
FileAppend,
(
PreferenceSettings:
%WindowsOnStartUp%n := %n%
MouseoverWidth := %MouseoverWidth%
UserHotkey = %UserHotkey%
UserUnhideHotkey = %UserUnhideHotkey%
UserSnapHotkey = %UserSnapHotkey%
gfx := %gfx%
HideColor = %HideColor%
UnhideColor = %UnhideColor%
Color = %HideColor%
MinimizeColor = %MinimizeColor%
GUIThickness := %GUIThickness%
return
), %A_ScriptFullPath%
reload
}

;=============================================End of Setup Section===================================================
;You can delete everything above this point after you run it the first time if you like, although it makes reconfiguration easier (delete the PreferenceSettings label and run again)

DetectHiddenWindows, on
#SingleInstance Force
SetWinDelay 10
SetKeyDelay 0
Coordmode Mouse
OnExit, ForceExit
Exiting := 0
GotoLabel = PreferenceSettings
Gosub %GotoLabel%

Hotkey, %UserHotkey%, AutoHide
Hotkey, %UserUnhideHotkey%, UnhideAll
Hotkey, %UserSnapHotkey%, SnapWindow

gosub ListHiddenWindows

settimer, Mouseover, 250

Mouseover:
MouseGetPos, MouseX, MouseY
loop %n%
{
	ifwinnotexist % "ahk_id " . HWND%A_Index%
	{
		gosub ClearName
		return
	}
	if Active%A_Index%
	{
		wingetpos, x, y, Width, Height, % "ahk_id " . HWND%A_Index%
		if (x <> x%A_Index%) or (y <> y%A_Index%) or (Width <> Width%A_Index%) or (Height <> Height%A_Index%)
		{
			Gosub GetScreenEdge
			x%A_Index% := x, y%A_Index% := y, Width%A_Index% := Width, Height%A_Index% := Height
		}
		Gosub % "Active" . ScreenEdge%A_Index%
	} else
		GoSub % "Hidden" . ScreenEdge%A_Index%
}
return

GetScreenEdge:
min := 10000
if (x < min)
	min := x, ScreenEdge%A_Index% := "Left"
if (y < min)
	min := y, ScreenEdge%A_Index% := "Top"
if ((A_ScreenWidth - 1 - x - Width) < min)
	min := A_ScreenWidth - 1 - x - Width, ScreenEdge%A_Index% := "Right"
if ((A_ScreenHeight - 1 - y - Height) < min)
	ScreenEdge%A_Index% := "Bottom"
if gfx = 0
	return
gui color, %Color%
gui 2:color, %Color%
gui 1:+ToolWindow -SysMenu -Caption +AlwaysOnTop
gui 2:+ToolWindow -SysMenu -Caption +AlwaysOnTop
if (ScreenEdge%A_Index% = "Top")
{
	v := y - GUIThickness
	if (y > 0)
		Gui 1:show, H%GUIThickness% W%Width% X%x% Y%v% NA
	Gui 2:show, H%GUIThickness% W%Width% X%x% Y0 NA
}
else if (ScreenEdge%A_Index% = "Left")
{
	v := x - GUIThickness
	if (x > 0)
		Gui 1:show, W%GUIThickness% H%Height% X%v% Y%y% NA
	Gui 2:show, W%GUIThickness% H%Height% X0 Y%y% NA
}
else if (ScreenEdge%A_Index% = "Right")
{
	v := x + Width
	if (v < A_ScreenWidth - 1)
		Gui 1:show, W%GUIThickness% H%Height% X%v% Y%y% NA
	v := A_ScreenWidth - GUIThickness
	Gui 2:show, W%GUIThickness% H%Height% X%v% Y%y% NA
}
else
{
	v := y + Height
	if (v < A_ScreenHeight - 1)
		Gui 1:show, H%GUIThickness% W%Width% X%x% Y%v% NA
	v := A_ScreenHeight - GUIThickness
	Gui 2:show, H%GUIThickness% W%Width% X%x% Y%v% NA
}
sleep 100
gui 1:destroy
gui 2:destroy
return

HiddenTop:
if MouseY <> 0
	return
if (MouseX < MouseoverLocation%A_Index%) or (MouseX > (MouseoverLocation%A_Index% + MouseoverWidth))
	return
winshow, % "ahk_id " . HWND%A_Index%
winactivate % "ahk_id " . HWND%A_Index%
Active%A_Index% = 1
gosub ListHiddenWindows
return

HiddenLeft:
if MouseX <> 0
	return
if (MouseY < MouseoverLocation%A_Index%) or (MouseY > (MouseoverLocation%A_Index% + MouseoverWidth))
	return
winshow, % "ahk_id " . HWND%A_Index%
winactivate % "ahk_id " . HWND%A_Index%
Active%A_Index% = 1
gosub ListHiddenWindows
return

HiddenRight:
if (MouseX <> A_ScreenWidth - 1)
	return
if (MouseY < MouseoverLocation%A_Index%) or (MouseY > (MouseoverLocation%A_Index% + MouseoverWidth))
	return
winshow, % "ahk_id " . HWND%A_Index%
winactivate % "ahk_id " . HWND%A_Index%
Active%A_Index% = 1
gosub ListHiddenWindows
return

HiddenBottom:
if (MouseY <> A_ScreenHeight - 1)
	return
if (MouseX < MouseoverLocation%A_Index%) or (MouseX > (MouseoverLocation%A_Index% + MouseoverWidth))
	return
winshow, % "ahk_id " . HWND%A_Index%
winactivate % "ahk_id " . HWND%A_Index%
Active%A_Index% = 1
gosub ListHiddenWindows
return

ActiveTop:
if (MouseY < y + Height)
if (x < MouseX) and (MouseX < x + Width)
	return
winhide % "ahk_id " . HWND%A_Index%
ifwinactive % "ahk_id " . HWND%A_Index%
send !{esc}
Active%A_Index% = 0
MouseoverLocation%A_Index% := (Width - MouseoverWidth) * x / (A_ScreenWidth - Width) + x
if (MouseoverLocation%A_Index% < -100)
	MouseoverLocation%A_Index% := -100
if (MouseoverLocation%A_Index% > A_ScreenWidth - 101)
	MouseoverLocation%A_Index% := A_ScreenWidth - 101
GUIX := x
XIncrement := (MouseoverLocation%A_Index% - x) / 10
GUIY := y + Height
YIncrement := -(y + Height) / 10
GUIWidth := Width
GUIHeight := GUIThickness
WidthIncrement := (Width - MouseoverWidth) / 10
HeightIncrement := 0
gosub MinimizeGUI
gosub ListHiddenWindows
return

ActiveLeft:
if (MouseX < x + Width)
if (y < MouseY) and (MouseY < y + Height)
	return
winhide % "ahk_id " . HWND%A_Index%
ifwinactive % "ahk_id " . HWND%A_Index%
send !{esc}
Active%A_Index% = 0
MouseoverLocation%A_Index% := (Height - MouseoverWidth) * y / (A_ScreenHeight - Height) + y
if (MouseoverLocation%A_Index% < -100)
	MouseoverLocation%A_Index% := -100
if (MouseoverLocation%A_Index% > A_ScreenHeight - 101)
	MouseoverLocation%A_Index% := A_ScreenHeight - 101
GUIX := x + Width
XIncrement := -(x + Width) / 10
GUIY := y
YIncrement := (MouseoverLocation%A_Index% - y) / 10
GUIWidth := GUIThickness
GUIHeight := Height
WidthIncrement := 0
HeightIncrement := (Height - MouseoverWidth) / 10
gosub MinimizeGUI
gosub ListHiddenWindows
return

ActiveRight:
if (MouseX > x)
if (y < MouseY) and (MouseY < y + Height)
	return
winhide % "ahk_id " . HWND%A_Index%
ifwinactive % "ahk_id " . HWND%A_Index%
send !{esc}
Active%A_Index% = 0
MouseoverLocation%A_Index% := (Height - MouseoverWidth) * y / (A_ScreenHeight - Height) + y
if (MouseoverLocation%A_Index% < -100)
	MouseoverLocation%A_Index% := -100
if (MouseoverLocation%A_Index% > A_ScreenHeight - 101)
	MouseoverLocation%A_Index% := A_ScreenHeight - 101
GUIX := x - GUIThickness
XIncrement := (A_ScreenWidth - x) / 10
GUIY := y
YIncrement := (MouseoverLocation%A_Index% - y) / 10
GUIWidth := GUIThickness
GUIHeight := Height
WidthIncrement := 0
HeightIncrement := (Height - MouseoverWidth) / 10
gosub MinimizeGUI
gosub ListHiddenWindows
return

ActiveBottom:
if (MouseY > y)
if (x < MouseX) and (MouseX < x + Width)
	return
winhide % "ahk_id " . HWND%A_Index%
ifwinactive % "ahk_id " . HWND%A_Index%
send !{esc}
Active%A_Index% = 0
MouseoverLocation%A_Index% := (Width - MouseoverWidth) * x / (A_ScreenWidth - Width) + x
if (MouseoverLocation%A_Index% < -100)
	MouseoverLocation%A_Index% := -100
if (MouseoverLocation%A_Index% > A_ScreenWidth - 101)
	MouseoverLocation%A_Index% := A_ScreenWidth - 101
GUIX := x
XIncrement := (MouseoverLocation%A_Index% - x) / 10
GUIY := y - GUIThickness
YIncrement := (A_ScreenHeight - y) / 10
GUIWidth := Width
GUIHeight := GUIThickness
WidthIncrement := (Width - MouseoverWidth) / 10
HeightIncrement := 0
gosub MinimizeGUI
gosub ListHiddenWindows
return

MinimizeGUI:
gui 3:color, %MinimizeColor%
gui 3:+ToolWindow -SysMenu -Caption +AlwaysOnTop
loop % gfx * 11
{
	gui 3:show, w%GUIWidth% h%GUIHeight% x%GUIX% y%GUIY% NA
	GUIX += XIncrement
	GUIY += YIncrement
	GUIWidth -= WidthIncrement
	GUIHeight -= HeightIncrement
	sleep %A_Index%
}
gui 3:destroy
return

ForceExit:
Exiting := 1
goto UnhideAll
return

UnhideAll:
loop %n%
{
	winshow % "ahk_id " . HWND%A_Index%
	winactivate % "ahk_id " . HWND%A_Index%
}
n := 0
if Exiting
exitapp
menu, tray, tip, AutoHide Windows
return

AutoHide:
ActiveWindow := WinExist("A")
loop % n + 1
{
	if (ActiveWindow = HWND%A_Index%)
	{
		Color := UnhideColor
		gosub GetScreenEdge
		Color := HideColor
		gosub ClearName
		return
	}
	if (A_Index = n + 1)
	{
		HWND%A_Index% := ActiveWindow
		Active%A_Index% = 1
	}
}
n++
gosub ListHiddenWindows
return

ClearName:
c := A_Index
loop % n - c
{
	d := c + 1
	Active%c% := Active%d%
	HWND%c% := HWND%d%
	MouseoverLocation%c% := MouseoverLocation%d%
	ScreenEdge%c% := ScreenEdge%d%
	x%c% := x%d%
	y%c% := y%d%
	Width%c% := Width%d%
	Height%c% := Height%d%
	c++
}
HWND%n% =
x%n% =
n--
gosub ListHiddenWindows
return

ListHiddenWindows:
if n = 0
{
	menu, tray, tip, AutoHide Windows
	return
}
TitleSum := "Windows AutoHidden:"
loop %n%
{
	if Active%A_Index% = 1
		continue
	WinGetTitle, title, % "ahk_id " . HWND%A_Index%
	TitleSum := TitleSum . "`n" . title
}
if (TitleSum = "Windows AutoHidden:")
menu, tray, tip, AutoHide Windows
else
menu, tray, tip, %TitleSum%
return

SnapWindow:
Already = 0
ActiveHWND := WinActive("A")
Loop % n + 1
{
	if (A_Index = n + 1)
	{
		HWND%A_Index% := ActiveHWND
		Active%A_Index% = 1
		n++
		wingetpos, x, y, Width, Height, % "ahk_id " . HWND%A_Index%
		Gosub GetScreenEdge
		gosub ListHiddenWindows
	}
	If (ActiveHWND = HWND%A_Index%)
		If not Active%A_Index%
			return
		else {
			If (ScreenEdge%A_Index% = "Top") {
				If (x%A_Index% < A_ScreenWidth - x%A_Index% - Width%A_Index% - 1)
					WinMove, % "ahk_ID " . HWND%A_Index%, , -1, -2
				Else
					WinMove, % "ahk_ID " . HWND%A_Index%, , A_ScreenWidth - Width%A_Index%, -2
			} Else If (ScreenEdge%A_Index% = "Left") {
				If (y%A_Index% < A_ScreenHeight - y%A_Index% - Height%A_Index% - 1)
					WinMove, % "ahk_ID " . HWND%A_Index%, , -2, -1
				Else {
					WinMove, % "ahk_ID " . HWND%A_Index%, , -2, A_ScreenHeight - Height%A_Index% + 1
					WinSet, alwaysontop, ON, % "ahk_ID " . HWND%A_Index%
				}
			} Else If (ScreenEdge%A_Index% = "Right") {
				If (y%A_Index% < A_ScreenHeight - y%A_Index% - Height%A_Index% - 1)
					WinMove, % "ahk_ID " . HWND%A_Index%, , A_ScreenWidth - Width%A_Index% + 2, -1
				Else {
					WinMove, % "ahk_ID " . HWND%A_Index%, , A_ScreenWidth - Width%A_Index% + 2, A_ScreenHeight - Height%A_Index% + 1
					WinSet, alwaysontop, ON, % "ahk_ID " . HWND%A_Index%
				}
			} Else If (ScreenEdge%A_Index% = "Bottom") {
				If (x%A_Index% < A_ScreenWidth - x%A_Index% - Width%A_Index% - 1)
					WinMove, % "ahk_ID " . HWND%A_Index%, , -1, A_ScreenHeight - Height%A_Index% + 2
				Else
					WinMove, % "ahk_ID " . HWND%A_Index%, , A_ScreenWidth - Width%A_Index% + 1, A_ScreenHeight - Height%A_Index% + 2
				WinSet, alwaysontop, ON, % "ahk_ID " . HWND%A_Index%
			}
			Gosub GetScreenEdge
			return
		}
}
return

;-----------------Special Winclose Key (to avoid closing hidden windows)------------
;This shouldn't be necessary, but I like to have a pause::winclose, A key anyway, and it was messing up if I didn't implement it like this

pause::
WindowToClose := WinExist("A")
loop %n%
	if (WindowToClose = HWND%A_Index%)
		if (0 = Active%A_Index%)
		{
			winclose Program Manager
			return
		}
send !{f4}{pause up}
return

;==============================User Defined Preferences===========================


Here's the code. The first part allows you to customize the script. Load it up and take it for a spin

Edit - I added a key, WIN + SHIFT + . (or caret, so I remember "to the side") combo that will move the current window to the nearest screen corner, autohide it if it isn't already hidden, and set it to "Always on top" if it is above the taskbar. (You'll need some kind of key to undo always on top if you want to un-autohide it.)

Ask me any questions you might have.

Ben

Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


schlice
  • Members
  • 4 posts
  • Last active: Oct 30 2015 05:09 PM
  • Joined: 02 Apr 2010
I was working on a totally different concept when I found your code. Very nice! I'm working up a GUI for the setup, moving the variables to INI files, and cleaning up some of the code. Should cut the script size in half and allow for creating EXE files too.

CJ

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
The program I posted here also has a feature like this.

Mauko24
  • Guests
  • Last active:
  • Joined: --
@fragman, i tried your neat program. lotsa potential. sliding windows do not work for me though. windows slide off screen but do not come back when cursor is at screen edge.

this script works well, just wish we would choose which side we hide our windows :)

berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009

this script works well, just wish we would choose which side we hide our windows :)


What do you mean by that? Have you tried dragging the window around the screen with autohiding on? It will readjust to whichever side is closest - i.e. you choose by positioning the window, if you want to choose the left side, drag it so that it is closer to the left than any other side

If you mean you hide a window hoping it'll go to the top or something and it actually turns out being closer to the top of the screen and goes there, well... that's just my personal preference to make it that way. You could easily change it so that the side it is closer to when you press the hotkey remains the hiding side (so then you can move the window wherever you want even if it is closer to another screen edge) by cutting the first 11 lines from the "getscreenedge" routine into the autohide routine.

Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


Mauko24
  • Guests
  • Last active:
  • Joined: --
i couldnt edit my last post but i figured out how to use different sides shortly after. its logical and intuitive! i was also pleased to find out that you can maximize and restore a window and the script will reslide the window to the same side as before.

berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009
haha actually that isn't the case for me... it seems to like the upper right corner when it's maximized. :? cool that you like it!!

Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009
Due to popular request, (i.e. I wanted it for myself), I have added a feature where you press a hotkey to move the window to the nearest screen corner, if it is being auto hidden, because I often feel like doing this but it's kind of a pain, especially when you have to make it always on top to go over the taskbar.

Edit - added this to the original code.

Find me on the new AutoHotkey forums and send me a message if you have a question about any of the scrips I've posted to this forum!


urlwolf
  • Members
  • 150 posts
  • Last active: Feb 26 2012 07:56 PM
  • Joined: 16 Mar 2006
First, let me say this is a great idea!
I'm hiding FreeCommander, but when I delete or move a file the popup window showing progress appears behind the main window. Is there anything that can be done to prevent this? Workarould?

Thanks!

berban_
  • Members
  • 202 posts
  • Last active: Aug 05 2014 11:52 PM
  • Joined: 16 Mar 2011
Hey urlwolf, glad you like the script!

As you can see, this script is super old! It was one of my first scripts, and desperately needs a rewrite. However, I have held off on updating it because it still works, and hey, what more can you ask for?

While I haven't rewritten the script, I have made little tweaks here and there to fix certain unique behaviors like the one you have come across. Unfortunately, in that particular case (where a hidden window spawns a child window which is visible), I generally just don't autohide the window because it's a pain do deal with that behavior.

If you want to macgyver a fix, I'd recommend some sort of timer (well, you can just add some statements to the timer that this script already needs.) You could hide all windows of that class or title. Or, a better (more advanced) way to do it would be to use the "GetParent" function.

;Check to see if a window is a child window by calling this DllCall and passing that window's ID where it says HWND below.
;If the window is a child window, the dllcall will return the ID (hwnd) of the parent window. Otherwise it will return false.
ParentWindowHWND := DllCall("GetParent", UInt, HWND)

Actually, now that I think about it, this isn't too advanced at all. In your timer you'd put a WinGet, , List call to retrieve the handles of all windows. Then check them one by one with the dllcall to see if they are child windows. If they are, check if the parent hwnd matches one of the windows that is currently being autohidden. If it does, hide that window.

Let me know if this makes sense :)

urlwolf
  • Members
  • 150 posts
  • Last active: Feb 26 2012 07:56 PM
  • Joined: 16 Mar 2006
Hmm, too complicated for the little ahk that I know. I'll monitor this thread in case you rewrite and update the script, though. Thanks!

potbellyninja
  • Guests
  • Last active:
  • Joined: --
I ran this script the first time and entered all the preferences. It was supposed to exit then relaunch, but it is in a continuous loop taking me back to set the preferences. Help.

berban_
  • Members
  • 202 posts
  • Last active: Aug 05 2014 11:52 PM
  • Joined: 16 Mar 2011
Potbellyninja: You need to use an .ahk file (i.e. not a compiled exe) and you should have it saved somewhere, as opposed to in a temporary location like temporary internet files. Let me know if you're still lost

UberSlackr
  • Members
  • 8 posts
  • Last active: Jun 23 2015 06:33 AM
  • Joined: 17 Mar 2012
When you copy the code from the original post.. Make sure you put a space(a blank line) at the very bottom of the .ahk file ( after "User Defined Preferences")

Otherwise when it writes the "Preferences" it start them on the same line as the commented ;======User...===== and the script will not read it... Therefore you are sent into a loop..

I know this is an old thread, but I just stumbled on it, and through I would mention this for anyone else that does.. so they don't have issues.

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
After skimming over the script I noticed two issues:
It does not seem to mve tool windows (didn't test so correct me if wrong).
It does not work properly for multi-monitor setups as A_Screen***** are used instead of the workspace area.