Jump to content

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

Windows-7 Like Window Positioning for XP and Vista


  • Please log in to reply
80 replies to this topic
  • Guests
  • Last active:
  • Joined: --

personally i would store the window size in RAM and skip the temporary file altogether.

At your request, here is a version that stores all information in the memory instead of a file.

#NoEnv
#Persistent

;--------------------------------------------detects closing windows

SetBatchLines, -1
Process, Priority,, High

Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam )
{
  Global ID
  If ( wParam = 2 ) {
   SetFormat, Integer, Hex
   ID := lParam + 0
   SetFormat, Integer, D
   SetTimer, MyRoutine, -1
  }
}

;---------------------------deletes stored data if window is closed

MyRoutine:
if %ID%check=1
	{
	%ID%check=
	%ID%width=
	%ID%height=
	}
Return

;-----------------------------------------handles desktop variables

Win__GetDesktopPos(ByRef X, ByRef Y, ByRef W, ByRef H)
	{
	WinGetPos, TrayX, TrayY, TrayW, TrayH, ahk_class Shell_TrayWnd
	if (TrayW = A_ScreenWidth)
		{
		X := 0
		Y := TrayY ? 0 : TrayH
		W := A_ScreenWidth
		H := A_ScreenHeight - TrayH
		}
	else
		{
		X := TrayX ? 0 : TrayW
		Y := 0
		W := A_ScreenWidth - TrayW
		H := A_ScreenHeight
		}
	}

;----------------------------------------handles left half maximize 

Win__HalfLeft()
{
WinGetActiveStats,Title,Width,Height,p,p
winget,ID#,ID,%Title%
Check=%ID#%check
if check=1
	{
	goto,skipleft
	}
%ID#%check=1
%ID#%Width=%width%
%ID#%Height=%height%
skipleft:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W/2, H
}

;----------------------------------------handles right half maximize

Win__HalfRight()
{	
WinGetActiveStats,Title,Width,Height,p,p
winget,ID#,ID,%Title%
Check=%ID#%check
if check=1
	{
	goto,skipright
	}
%ID#%check=1
%ID#%Width=%width%
%ID#%Height=%height%
skipright:
Win__GetDesktopPos(X, Y, W, H)
winMove, A,, X + W/2, Y, W/2, H
}

;----------------------------------------handles full maximize 

Win__FullSize()
{
WinGetActiveStats,Title,Width,Height,p,p
winget,ID#,ID,%Title%
Check=%ID#%check
if check=1
	{
	goto,skipfull
	}
%ID#%check=1
%ID#%Width=%width%
%ID#%Height=%height%
skipfull:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W, H
}

;-----------------------detects when window is being dragged

*~LButton::
 CoordMode, Mouse, Screen
 MouseGetPos, x, y, hwnd
 SendMessage, 0x84, 0, (x&0xFFFF) | (y&0xFFFF) << 16,, ahk_id %hwnd%
 RegExMatch("ERROR TRANSPARENT NOWHERE CLIENT CAPTION SYSMENU SIZE MENU HSCROLL VSCROLL MINBUTTON MAXBUTTON LEFT RIGHT TOP TOPLEFT TOPRIGHT BOTTOM BOTTOMLEFT BOTTOMRIGHT BORDER OBJECT CLOSE HELP", "(?:\w+\s+){" . ErrorLevel+2&0xFFFFFFFF . "}(?<AREA>\w+\b)", HT)
 if htarea!=CAPTION
	Return
 MouseGetPos,_x,_y
 While GetKeyState("LButton","P") && x=_x && y=_y
	MouseGetPos,_x,_y

;---------detects when mouse is moved to the edge of screen

 if GetKeyState("LButton","P")=1
	{ 
	keywait,lbutton
	wingetactivestats,ActiveTitle,Width,Height,x,Y
	winget,test,MinMax,%activetitle%
	if test=1
		{
		return
		}
	coordmode,mouse,screen
	MouseGetPos,Mouse_X,Mouse_Y
	if Mouse_X=0
		{
		Win__HalfLeft()
		return
		}
	Win__GetDesktopPos(X,Y,Width,Height)	
	Width-=5
	if (width < mouse_x)
		{
		Win__HalfRight()
		return
		}
	if mouse_y=0
		{
		Win__FullSize()
		return
		}

;----------calculates restored window size and location

	WinGetActiveStats,Title,Width,Height,p,p
	winget,ID#,ID,%Title%
	Check=%ID#%check
	if check=1
		{
		return
		}
	if check=1
		{
		Originalwidth=%ID#%Width
		Originalheight=%ID#%height
		%ID#%check=
		%ID#%Width=
		%ID#%height=
		WinGetActiveStats,ActiveTitle,total,CurrentHeight,p,p
		coordmode,mouse,relative
		MouseGetPos,given
		Calc:= given / total
		Calc:= Calc*100
		Calc:= Calc / 100
		Calc:= Calc*originalwidth
		coordmode,mouse,screen
		MouseGetPos,mouse_x
		Win__GetDesktopPos(X,Y,Width,Height) 
		Calc2:= width-mouse_x
		Calc2:= Calc2+Calc
		Calc2:= width-Calc2
		Calc:=Calc2+originalwidth
		coordmode,mouse,screen
		MouseGetPos,mouse
		Calc:=Calc-mouse
		mouse:=mouse-Calc2
		mouse1:=23-mouse
		if mouse<23
			{
			Calc2:=Calc2-mouse1
			}
		if Calc<75
			{
			Calc:=80-Calc
			Calc2:=Calc2+Calc
			}		
		winmove,%ActiveTitle%,,%Calc2%,,%originalwidth%,%originalheight%
		return
		}
	}
Return

;--------------------------------------Shortcut keys

#right::Win__HalfRight()
#left::Win__HalfLeft()
#up::Win__FullSize()

The next and most likely last version will incorporate live preview of window size changes in a smooth method, I believe I know a way I can achieve this.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
ignore last post, there was an error

#Persistent

;--------------------------------------------detects closing windows

SetBatchLines, -1
Process, Priority,, High

Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam )
{
  Global ID
  If ( wParam = 2 ) {
   SetFormat, Integer, Hex
   ID := lParam + 0
   SetFormat, Integer, D
   SetTimer, MyRoutine, -1
  }
}

;---------------------------deletes stored data if window is closed

MyRoutine:
if %ID%check=1
	{
	%ID%check:=
	%ID%width:=
	%ID%height:=
	}
Return

;-----------------------------------------handles desktop variables

Win__GetDesktopPos(ByRef X, ByRef Y, ByRef W, ByRef H)
	{
	WinGetPos, TrayX, TrayY, TrayW, TrayH, ahk_class Shell_TrayWnd
	if (TrayW = A_ScreenWidth)
		{
		X := 0
		Y := TrayY ? 0 : TrayH
		W := A_ScreenWidth
		H := A_ScreenHeight - TrayH
		}
	else
		{
		X := TrayX ? 0 : TrayW
		Y := 0
		W := A_ScreenWidth - TrayW
		H := A_ScreenHeight
		}
	}

;----------------------------------------handles left half maximize 

Win__HalfLeft()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipleft1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
check2:=%id%height
ID=
skipleft1:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W/2, H
return
}

;----------------------------------------handles right half maximize

Win__HalfRight()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipright1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
check2:=%id%height
ID=
skipright1:
Win__GetDesktopPos(X, Y, W, H)
winMove, A,, X + W/2, Y, W/2, H
return
}

;----------------------------------------handles full maximize 

Win__FullSize()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipfull1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
check2:=%id%height
ID=
skipfull1:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W, H
return
}

;-----------------------detects when window is being dragged

*~LButton::
 CoordMode, Mouse, Screen
 MouseGetPos, x, y, hwnd
 SendMessage, 0x84, 0, (x&0xFFFF) | (y&0xFFFF) << 16,, ahk_id %hwnd%
 RegExMatch("ERROR TRANSPARENT NOWHERE CLIENT CAPTION SYSMENU SIZE MENU HSCROLL VSCROLL MINBUTTON MAXBUTTON LEFT RIGHT TOP TOPLEFT TOPRIGHT BOTTOM BOTTOMLEFT BOTTOMRIGHT BORDER OBJECT CLOSE HELP", "(?:\w+\s+){" . ErrorLevel+2&0xFFFFFFFF . "}(?<AREA>\w+\b)", HT)
 if htarea!=CAPTION
	Return
 MouseGetPos,_x,_y
 While GetKeyState("LButton","P") && x=_x && y=_y

	MouseGetPos,_x,_y
	keywait,lbutton
	wingetactivestats,ActiveTitle,Width,Height,x,Y
	winget,test,MinMax,%activetitle%
	if test=1
		{
		return
		}
	coordmode,mouse,screen
	MouseGetPos,Mouse_X,Mouse_Y
	if Mouse_X=0
		{	;-----------------------------------------left
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		check:=%id%check
		if check=1
			{
			goto,skipleft
			}
		%ID%check=1
		%ID%Width=%width%
		%ID%Height=%height%
		check2:=%id%height
		ID=
		skipleft:
		Win__GetDesktopPos(X, Y, W, H)
		WinMove, A,, X, Y, W/2, H
		return
		}
	Win__GetDesktopPos(X,Y,Width,Height)	
	Width-=5
	if (width < mouse_x)
		{	;-----------------------------------------right
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		check:=%id%check
		if check=1
			{
			goto,skipright
			}
		%ID%check=1
		%ID%Width=%width%
		%ID%Height=%height%
		check2:=%id%height
		ID=
		skipright:
		Win__GetDesktopPos(X, Y, W, H)
		winMove, A,, X + W/2, Y, W/2, H
		return
		}
	if mouse_y=0
		{	;-----------------------------------------full
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		check:=%id%check
		if check=1
			{
			goto,skipfull
			}
		%ID%check=1
		%ID%Width=%width%
		%ID%Height=%height%
		check2:=%id%height
		ID=
		skipfull:
		Win__GetDesktopPos(X, Y, W, H)
		WinMove, A,, X, Y, W, H
		return
		}
	WinGetActiveStats,Title,Width,Height,X,Y
	winget,ID,ID,%Title%
	check:=%id%check
	if check=1
		{
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		Originalwidth:=%ID%Width
		Originalheight:=%ID%height
		%ID%check=
		%ID%Width=
		%ID%height=
		%ID%=
		WinGetActiveStats,ActiveTitle,total,CurrentHeight,p,p
		coordmode,mouse,relative
		MouseGetPos,given
		Calc:= given / total
		Calc:= Calc*100
		Calc:= Calc / 100
		Calc:= Calc*originalwidth
		coordmode,mouse,screen
		MouseGetPos,mouse_x
		Win__GetDesktopPos(X,Y,Width,Height) 
		Calc2:= width-mouse_x
		Calc2:= Calc2+Calc
		Calc2:= width-Calc2
		Calc:=Calc2+originalwidth
		coordmode,mouse,screen
		MouseGetPos,mouse
		Calc:=Calc-mouse
		mouse:=mouse-Calc2
		mouse1:=23-mouse
		if mouse<23
			{
			Calc2:=Calc2-mouse1
			}
		if Calc<75
			{
			Calc:=80-Calc
			Calc2:=Calc2+Calc
			}		
		winmove,%ActiveTitle%,,%Calc2%,,%originalwidth%,%originalheight%
		return
		}
	
Return

;--------------------------------------Shortcut keys

#right::Win__HalfRight()
#left::Win__HalfLeft()
#up::Win__FullSize()


KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Live previews are now supported.

#Persistent

;--------------------------------------------detects closing windows

SetBatchLines, -1
Process, Priority,, High

Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam )
{
  Global ID
  If ( wParam = 2 ) {
   SetFormat, Integer, Hex
   ID := lParam + 0
   SetFormat, Integer, D
   SetTimer, MyRoutine, -1
  }
}

;---------------------------deletes stored data if window is closed

MyRoutine:
if %ID%check=1
	{
	%ID%check=
	%ID%width=
	%ID%height=
	%ID%X=
	}
Return

;-----------------------------------------handles desktop variables

Win__GetDesktopPos(ByRef X, ByRef Y, ByRef W, ByRef H)
	{
	WinGetPos, TrayX, TrayY, TrayW, TrayH, ahk_class Shell_TrayWnd
	if (TrayW = A_ScreenWidth)
		{
		X := 0
		Y := TrayY ? 0 : TrayH
		W := A_ScreenWidth
		H := A_ScreenHeight - TrayH
		}
	else
		{
		X := TrayX ? 0 : TrayW
		Y := 0
		W := A_ScreenWidth - TrayW
		H := A_ScreenHeight
		}
	}

;----------------------------------------handles left half maximize 

Win__HalfLeft()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipleft1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
ID=
skipleft1:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W/2, H
return
}

;----------------------------------------handles right half maximize

Win__HalfRight()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipright1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
ID=
skipright1:
Win__GetDesktopPos(X, Y, W, H)
winMove, A,, X + W/2, Y, W/2, H
return
}

;----------------------------------------handles full maximize 

Win__FullSize()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipfull1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
ID=
skipfull1:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W, H
return
}

;-----------------------detects when window is being dragged

*~LButton::
 CoordMode, Mouse, Screen
 MouseGetPos, x, y, hwnd
 SendMessage, 0x84, 0, (x&0xFFFF) | (y&0xFFFF) << 16,, ahk_id %hwnd%
 RegExMatch("ERROR TRANSPARENT NOWHERE CLIENT CAPTION SYSMENU SIZE MENU HSCROLL VSCROLL MINBUTTON MAXBUTTON LEFT RIGHT TOP TOPLEFT TOPRIGHT BOTTOM BOTTOMLEFT BOTTOMRIGHT BORDER OBJECT CLOSE HELP", "(?:\w+\s+){" . ErrorLevel+2&0xFFFFFFFF . "}(?<AREA>\w+\b)", HT)
 if htarea!=CAPTION
	Return
 MouseGetPos,_x,_y
 While GetKeyState("LButton","P") && x=_x && y=_y
	{
	start:
	sleep 50
	wingetactivestats,ActiveTitle,Width,Height,x,Y
	winget,test,MinMax,%activetitle%
	if test=1
		{
		return
		}
	coordmode,mouse,screen
	MouseGetPos,Mouse_X,Mouse_Y
	if Mouse_X=0
		{	;-----------------------------------------left
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		check:=%id%check
		if check=1
			{
			goto,skipleft
			}
		%ID%check=1
		%ID%Width=%width%
		%ID%Height=%height%
		%ID%x=%x%
		ID=
		skipleft:
		click up
		Win__GetDesktopPos(X, Y, W, H)
		WinMove, A,, X, Y, W/2, H
		loop
			{
			sleep 50
			coordmode,mouse,screen
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				return
				}
			if Mouse_X>0
				{
				WinGetActiveStats,Title,Width,Height,X,Y
				winget,ID,ID,%Title%
				Originalwidth:=%ID%Width
				Originalheight:=%ID%height
				%ID%check=
				%ID%Width=
				%ID%height=
				WinGetActiveStats,ActiveTitle,total,CurrentHeight,p,p
				coordmode,mouse,relative
				MouseGetPos,given
				Calc:= given / total
				Calc:= Calc*100
				Calc:= Calc / 100
				Calc:= Calc*originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse_x
				Win__GetDesktopPos(X,Y,Width,Height) 
				Calc2:= width-mouse_x
				Calc2:= Calc2+Calc
				Calc2:= width-Calc2
				Calc:=Calc2+originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse
				Calc:=Calc-mouse
				mouse:=mouse-Calc2
				mouse1:=23-mouse
				if mouse<23
					{
					Calc2:=Calc2-mouse1
					}
				if Calc<75
					{
					Calc:=80-Calc
					Calc2:=Calc2+Calc
					}
				coordmode,mouse,screen
				MouseGetPos,mouse_x,mouse_y
				mouse_y:=mouse_y-8
				originalx:=%ID%x
				winmove,%ActiveTitle%,,%originalx%,%mouse_y%,%originalwidth%,%originalheight%
				mouse_y:=mouse_y+18
				click,1,%mouse_y%,  down
				ID=
				%ID%x=
				goto,start
				}
			}
		}
	Win__GetDesktopPos(X,Y,Width,Height)	
	Width-=5
	if (width < mouse_x)
		{	;-----------------------------------------right
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		check:=%id%check
		if check=1
			{
			goto,skipright
			}
		%ID%check=1
		%ID%Width=%width%
		%ID%Height=%height%
		%ID%x=%x%
		ID=
		skipright:
		click up
		Win__GetDesktopPos(X, Y, W, H)
		winMove, A,, X + W/2, Y, W/2, H
		loop
			{
			sleep 50
			coordmode,mouse,screen
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				return
				}
			Win__GetDesktopPos(X,Y,Width,Height)	
			Width-=5
			if (width > mouse_x)
				{
				WinGetActiveStats,Title,Width,Height,X,Y
				winget,ID,ID,%Title%
				Originalwidth:=%ID%Width
				Originalheight:=%ID%height
				%ID%check=
				%ID%Width=
				%ID%height=
				WinGetActiveStats,ActiveTitle,total,CurrentHeight,p,p
				coordmode,mouse,relative
				MouseGetPos,given
				Calc:= given / total
				Calc:= Calc*100
				Calc:= Calc / 100
				Calc:= Calc*originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse_x
				Win__GetDesktopPos(X,Y,Width,Height) 
				Calc2:= width-mouse_x
				Calc2:= Calc2+Calc
				Calc2:= width-Calc2
				Calc:=Calc2+originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse
				Calc:=Calc-mouse
				mouse:=mouse-Calc2
				mouse1:=23-mouse
				if mouse<23
					{
					Calc2:=Calc2-mouse1
					}
				if Calc<75
					{
					Calc:=80-Calc
					Calc2:=Calc2+Calc
					}
				coordmode,mouse,screen
				MouseGetPos,mouse_x,mouse_y
				mouse_y:=mouse_y-8
				originalx:=%ID%x
				winmove,%ActiveTitle%,,%originalx%,%mouse_y%,%originalwidth%,%originalheight%
				mouse_y:=mouse_y+15
				Win__GetDesktopPos(X,Y,Width,Height) 
				width:=width-5
				click,%width%,%mouse_y%,  down
				ID=
				%ID%x=
				goto,start
				}
			}
		}
	if mouse_y=0
		{	;-----------------------------------------full
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		check:=%id%check
		if check=1
			{
			goto,skipfull
			}
		%ID%check=1
		%ID%Width=%width%
		%ID%Height=%height%
		%ID%x=%x%
		ID=
		skipfull:
		click up
		Win__GetDesktopPos(X, Y, W, H)
		WinMove, A,, X, Y, W, H
		loop
			{
			sleep 50
			coordmode,mouse,screen
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				return
				}
			if mouse_y>3
				{
				WinGetActiveStats,Title,Width,Height,X,Y
				winget,ID,ID,%Title%
				Originalwidth:=%ID%Width
				Originalheight:=%ID%height
				%ID%check=
				%ID%Width=
				%ID%height=
				WinGetActiveStats,ActiveTitle,total,CurrentHeight,p,p
				coordmode,mouse,relative
				MouseGetPos,given
				Calc:= given / total
				Calc:= Calc*100
				Calc:= Calc / 100
				Calc:= Calc*originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse_x
				Win__GetDesktopPos(X,Y,Width,Height) 
				Calc2:= width-mouse_x
				Calc2:= Calc2+Calc
				Calc2:= width-Calc2
				Calc:=Calc2+originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse
				Calc:=Calc-mouse
				mouse:=mouse-Calc2
				mouse1:=23-mouse
				if mouse<23
					{
					Calc2:=Calc2-mouse1
					}
				if Calc<75
					{
					Calc:=80-Calc
					Calc2:=Calc2+Calc
					}		
				winmove,%ActiveTitle%,,%Calc2%,,%originalwidth%,%originalheight%
				coordmode,mouse,screen
				MouseGetPos,mouse
				mouse:=mouse+2
				click,%mouse%,5,  down
				ID=
				%ID%x=
				goto,start
				}
			}
		}
	WinGetActiveStats,Title,Width,Height,X,Y
	winget,ID,ID,%Title%
	check:=%id%check
	if check=1
		{
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		Originalwidth:=%ID%Width
		Originalheight:=%ID%height
		%ID%check=
		%ID%Width=
		%ID%height=
		%ID%=
		WinGetActiveStats,ActiveTitle,total,CurrentHeight,p,p
		coordmode,mouse,relative
		MouseGetPos,given
		Calc:= given / total
		Calc:= Calc*100
		Calc:= Calc / 100
		Calc:= Calc*originalwidth
		coordmode,mouse,screen
		MouseGetPos,mouse_x
		Win__GetDesktopPos(X,Y,Width,Height) 
		Calc2:= width-mouse_x
		Calc2:= Calc2+Calc
		Calc2:= width-Calc2
		Calc:=Calc2+originalwidth
		coordmode,mouse,screen
		MouseGetPos,mouse
		Calc:=Calc-mouse
		mouse:=mouse-Calc2
		mouse1:=23-mouse
		if mouse<23
			{
			Calc2:=Calc2-mouse1
			}
		if Calc<75
			{
			Calc:=80-Calc
			Calc2:=Calc2+Calc
			}		
		winmove,%ActiveTitle%,,%Calc2%,,%originalwidth%,%originalheight%
		ID=
		%ID%x=
		goto,start
		}
	If (GetKeyState("LButton","P")=0)
		{
		return
		}
	goto,start
	}
Return

;--------------------------------------Shortcut keys

#right::Win__HalfRight()
#left::Win__HalfLeft()
#up::Win__FullSize()


ACLarrabee3
  • Guests
  • Last active:
  • Joined: --
pressing the "start" button messes everything up..
the start menu shoots up half the screen, and i get this error


Error: This dynamic variable is blank. If this variable was not intended to be dynamic, remove the % symbols from it.

Specifically: %ID%

Line#
385: WinGetPos,x,y,Width,Height,A
386: WinGet,ID,ID,%Title%
387: Originalwidth := %ID%Width
388: Originalheight := %ID%height
389: %ID%check =
390: %ID%Width =
391: %ID%height =
---> 392: %ID% =
393: WinGetTitle,ActiveTitle,A
393: WinGetPos,p,p,total,CurrentHeight,A
394: CoordMode,mouse,relative
395: MouseGetPos,given
396: Calc := given / total
397: Calc := Calc*100
398: Calc := Calc / 100

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Forgot to remove that line. See if you can get the same error now.

#Persistent

;--------------------------------------------detects closing windows

SetBatchLines, -1
Process, Priority,, High

Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam )
{
  Global ID
  If ( wParam = 2 ) {
   SetFormat, Integer, Hex
   ID := lParam + 0
   SetFormat, Integer, D
   SetTimer, MyRoutine, -1
  }
}

;---------------------------deletes stored data if window is closed

MyRoutine:
if %ID%check=1
	{
	%ID%check=
	%ID%width=
	%ID%height=
	%ID%X=
	}
Return

;-----------------------------------------handles desktop variables

Win__GetDesktopPos(ByRef X, ByRef Y, ByRef W, ByRef H)
	{
	WinGetPos, TrayX, TrayY, TrayW, TrayH, ahk_class Shell_TrayWnd
	if (TrayW = A_ScreenWidth)
		{
		X := 0
		Y := TrayY ? 0 : TrayH
		W := A_ScreenWidth
		H := A_ScreenHeight - TrayH
		}
	else
		{
		X := TrayX ? 0 : TrayW
		Y := 0
		W := A_ScreenWidth - TrayW
		H := A_ScreenHeight
		}
	}

;----------------------------------------handles left half maximize 

Win__HalfLeft()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipleft1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
ID=
skipleft1:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W/2, H
return
}

;----------------------------------------handles right half maximize

Win__HalfRight()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipright1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
ID=
skipright1:
Win__GetDesktopPos(X, Y, W, H)
winMove, A,, X + W/2, Y, W/2, H
return
}

;----------------------------------------handles full maximize 

Win__FullSize()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipfull1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
ID=
skipfull1:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W, H
return
}

;-----------------------detects when window is being dragged

*~LButton::
 CoordMode, Mouse, Screen
 MouseGetPos, x, y, hwnd
 SendMessage, 0x84, 0, (x&0xFFFF) | (y&0xFFFF) << 16,, ahk_id %hwnd%
 RegExMatch("ERROR TRANSPARENT NOWHERE CLIENT CAPTION SYSMENU SIZE MENU HSCROLL VSCROLL MINBUTTON MAXBUTTON LEFT RIGHT TOP TOPLEFT TOPRIGHT BOTTOM BOTTOMLEFT BOTTOMRIGHT BORDER OBJECT CLOSE HELP", "(?:\w+\s+){" . ErrorLevel+2&0xFFFFFFFF . "}(?<AREA>\w+\b)", HT)
 if htarea!=CAPTION
	Return
 MouseGetPos,_x,_y
 While GetKeyState("LButton","P") && x=_x && y=_y
	{
	start:
	sleep 50
	wingetactivestats,ActiveTitle,Width,Height,x,Y
	winget,test,MinMax,%activetitle%
	if test=1
		{
		return
		}
	coordmode,mouse,screen
	MouseGetPos,Mouse_X,Mouse_Y
	if Mouse_X=0
		{	;-----------------------------------------left
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		check:=%id%check
		if check=1
			{
			goto,skipleft
			}
		%ID%check=1
		%ID%Width=%width%
		%ID%Height=%height%
		%ID%x=%x%
		ID=
		skipleft:
		click up
		Win__GetDesktopPos(X, Y, W, H)
		WinMove, A,, X, Y, W/2, H
		loop
			{
			sleep 50
			coordmode,mouse,screen
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				return
				}
			if Mouse_X>0
				{
				WinGetActiveStats,Title,Width,Height,X,Y
				winget,ID,ID,%Title%
				Originalwidth:=%ID%Width
				Originalheight:=%ID%height
				%ID%check=
				%ID%Width=
				%ID%height=
				WinGetActiveStats,ActiveTitle,total,CurrentHeight,p,p
				coordmode,mouse,relative
				MouseGetPos,given
				Calc:= given / total
				Calc:= Calc*100
				Calc:= Calc / 100
				Calc:= Calc*originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse_x
				Win__GetDesktopPos(X,Y,Width,Height) 
				Calc2:= width-mouse_x
				Calc2:= Calc2+Calc
				Calc2:= width-Calc2
				Calc:=Calc2+originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse
				Calc:=Calc-mouse
				mouse:=mouse-Calc2
				mouse1:=23-mouse
				if mouse<23
					{
					Calc2:=Calc2-mouse1
					}
				if Calc<75
					{
					Calc:=80-Calc
					Calc2:=Calc2+Calc
					}
				coordmode,mouse,screen
				MouseGetPos,mouse_x,mouse_y
				mouse_y:=mouse_y-8
				originalx:=%ID%x
				winmove,%ActiveTitle%,,%originalx%,%mouse_y%,%originalwidth%,%originalheight%
				mouse_y:=mouse_y+18
				click,1,%mouse_y%,  down
				ID=
				%ID%x=
				goto,start
				}
			}
		}
	Win__GetDesktopPos(X,Y,Width,Height)	
	Width-=5
	if (width < mouse_x)
		{	;-----------------------------------------right
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		check:=%id%check
		if check=1
			{
			goto,skipright
			}
		%ID%check=1
		%ID%Width=%width%
		%ID%Height=%height%
		%ID%x=%x%
		ID=
		skipright:
		click up
		Win__GetDesktopPos(X, Y, W, H)
		winMove, A,, X + W/2, Y, W/2, H
		loop
			{
			sleep 50
			coordmode,mouse,screen
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				return
				}
			Win__GetDesktopPos(X,Y,Width,Height)	
			Width-=5
			if (width > mouse_x)
				{
				WinGetActiveStats,Title,Width,Height,X,Y
				winget,ID,ID,%Title%
				Originalwidth:=%ID%Width
				Originalheight:=%ID%height
				%ID%check=
				%ID%Width=
				%ID%height=
				WinGetActiveStats,ActiveTitle,total,CurrentHeight,p,p
				coordmode,mouse,relative
				MouseGetPos,given
				Calc:= given / total
				Calc:= Calc*100
				Calc:= Calc / 100
				Calc:= Calc*originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse_x
				Win__GetDesktopPos(X,Y,Width,Height) 
				Calc2:= width-mouse_x
				Calc2:= Calc2+Calc
				Calc2:= width-Calc2
				Calc:=Calc2+originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse
				Calc:=Calc-mouse
				mouse:=mouse-Calc2
				mouse1:=23-mouse
				if mouse<23
					{
					Calc2:=Calc2-mouse1
					}
				if Calc<75
					{
					Calc:=80-Calc
					Calc2:=Calc2+Calc
					}
				coordmode,mouse,screen
				MouseGetPos,mouse_x,mouse_y
				mouse_y:=mouse_y-8
				originalx:=%ID%x
				winmove,%ActiveTitle%,,%originalx%,%mouse_y%,%originalwidth%,%originalheight%
				mouse_y:=mouse_y+15
				Win__GetDesktopPos(X,Y,Width,Height) 
				width:=width-5
				click,%width%,%mouse_y%,  down
				ID=
				%ID%x=
				goto,start
				}
			}
		}
	if mouse_y=0
		{	;-----------------------------------------full
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		check:=%id%check
		if check=1
			{
			goto,skipfull
			}
		%ID%check=1
		%ID%Width=%width%
		%ID%Height=%height%
		%ID%x=%x%
		ID=
		skipfull:
		click up
		Win__GetDesktopPos(X, Y, W, H)
		WinMove, A,, X, Y, W, H
		loop
			{
			sleep 50
			coordmode,mouse,screen
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				return
				}
			if mouse_y>3
				{
				WinGetActiveStats,Title,Width,Height,X,Y
				winget,ID,ID,%Title%
				Originalwidth:=%ID%Width
				Originalheight:=%ID%height
				%ID%check=
				%ID%Width=
				%ID%height=
				WinGetActiveStats,ActiveTitle,total,CurrentHeight,p,p
				coordmode,mouse,relative
				MouseGetPos,given
				Calc:= given / total
				Calc:= Calc*100
				Calc:= Calc / 100
				Calc:= Calc*originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse_x
				Win__GetDesktopPos(X,Y,Width,Height) 
				Calc2:= width-mouse_x
				Calc2:= Calc2+Calc
				Calc2:= width-Calc2
				Calc:=Calc2+originalwidth
				coordmode,mouse,screen
				MouseGetPos,mouse
				Calc:=Calc-mouse
				mouse:=mouse-Calc2
				mouse1:=23-mouse
				if mouse<23
					{
					Calc2:=Calc2-mouse1
					}
				if Calc<75
					{
					Calc:=80-Calc
					Calc2:=Calc2+Calc
					}		
				winmove,%ActiveTitle%,,%Calc2%,,%originalwidth%,%originalheight%
				coordmode,mouse,screen
				MouseGetPos,mouse
				mouse:=mouse+2
				click,%mouse%,5,  down
				ID=
				%ID%x=
				goto,start
				}
			}
		}
	WinGetActiveStats,Title,Width,Height,X,Y
	winget,ID,ID,%Title%
	check:=%id%check
	if check=1
		{
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		Originalwidth:=%ID%Width
		Originalheight:=%ID%height
		%ID%check=
		%ID%Width=
		%ID%height=
		WinGetActiveStats,ActiveTitle,total,CurrentHeight,p,p
		coordmode,mouse,relative
		MouseGetPos,given
		Calc:= given / total
		Calc:= Calc*100
		Calc:= Calc / 100
		Calc:= Calc*originalwidth
		coordmode,mouse,screen
		MouseGetPos,mouse_x
		Win__GetDesktopPos(X,Y,Width,Height) 
		Calc2:= width-mouse_x
		Calc2:= Calc2+Calc
		Calc2:= width-Calc2
		Calc:=Calc2+originalwidth
		coordmode,mouse,screen
		MouseGetPos,mouse
		Calc:=Calc-mouse
		mouse:=mouse-Calc2
		mouse1:=23-mouse
		if mouse<23
			{
			Calc2:=Calc2-mouse1
			}
		if Calc<75
			{
			Calc:=80-Calc
			Calc2:=Calc2+Calc
			}		
		winmove,%ActiveTitle%,,%Calc2%,,%originalwidth%,%originalheight%
		ID=
		%ID%x=
		goto,start
		}
	If (GetKeyState("LButton","P")=0)
		{
		return
		}
	goto,start
	}
Return

;--------------------------------------Shortcut keys

#right::Win__HalfRight()
#left::Win__HalfLeft()
#up::Win__FullSize()


KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Much more stable version, looks alot more like windows 7 version too.

#Persistent

;--------------------------------------------detects closing windows

SetBatchLines, -1
Process, Priority,, High

Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam )
{
  Global ID
  If ( wParam = 2 ) {
   SetFormat, Integer, Hex
   ID := lParam + 0
   SetFormat, Integer, D
   SetTimer, MyRoutine, -1
  }
}

;---------------------------deletes stored data if window is closed

MyRoutine:
if %ID%check=1
	{
	%ID%check=
	%ID%width=
	%ID%height=
	%ID%X=
	}
Return

;-----------------------------------------handles desktop variables

Win__GetDesktopPos(ByRef X, ByRef Y, ByRef W, ByRef H)
	{
	WinGetPos, TrayX, TrayY, TrayW, TrayH, ahk_class Shell_TrayWnd
	if (TrayW = A_ScreenWidth)
		{
		X := 0
		Y := TrayY ? 0 : TrayH
		}
	else
		{
		X := TrayX ? 0 : TrayW
		Y := 0
		}
	SysGet, MonitorWorkArea, MonitorWorkArea
	SysGet, Width, 78
	W=%MonitorWorkAreaRight%
	W:=width-2
	H=%MonitorWorkAreaBottom%
	}

;----------------------------------------handles left half maximize 

Win__HalfLeft()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipleft1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
ID=
skipleft1:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W/2, H
return
}

;----------------------------------------handles right half maximize

Win__HalfRight()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipright1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
ID=
skipright1:
Win__GetDesktopPos(X, Y, W, H)
winMove, A,, X + W/2, Y, W/2, H
return
}

;----------------------------------------handles full maximize 

Win__FullSize()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipfull1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
ID=
skipfull1:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W, H
return
}

;-----------------------detects when window is being dragged

*~LButton::
 CoordMode, Mouse, Screen
 MouseGetPos, x, y, hwnd
 SendMessage, 0x84, 0, (x&0xFFFF) | (y&0xFFFF) << 16,, ahk_id %hwnd%
 RegExMatch("ERROR TRANSPARENT NOWHERE CLIENT CAPTION SYSMENU SIZE MENU HSCROLL VSCROLL MINBUTTON MAXBUTTON LEFT RIGHT TOP TOPLEFT TOPRIGHT BOTTOM BOTTOMLEFT BOTTOMRIGHT BORDER OBJECT CLOSE HELP", "(?:\w+\s+){" . ErrorLevel+2&0xFFFFFFFF . "}(?<AREA>\w+\b)", HT)
 if htarea!=CAPTION
	Return
 MouseGetPos,_x,_y
 While GetKeyState("LButton","P") && x=_x && y=_y
	{
	start:
	sleep 50
	wingetactivestats,ActiveTitle,Width,Height,x,Y
	winget,test,MinMax,%activetitle%
	if test=1
		{
		return
		}
	coordmode,mouse,screen
	MouseGetPos,Mouse_X,Mouse_Y
	if Mouse_X=0
		{	;-----------------------------------------left
		detecthiddenwindows ,on
		splashimage,shade.jpg,hide b2
		WinSet, Transparent, 85, %A_ScriptName%
		Win__GetDesktopPos(X, Y, W, H)
		x:=x+3
		y:=y+3
		w:=w-6
		h:=h-6
		winmove,%A_ScriptName%,,x,y,w/2,%h%
		sleep 10
		SplashImage, Show, b2,,, SplashImage
		loop
			{
			sleep 50
			coordmode,mouse,screen
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				WinGetActiveStats,Title,Width,Height,X,Y
				winget,ID,ID,%Title%
				check:=%id%check
				if check=1
					{
					goto,skipleft
					}
				%ID%check=1
				%ID%Width=%width%
				%ID%Height=%height%
				%ID%x=%x%
				ID=
				skipleft:
				splashimage,off
				Win__GetDesktopPos(X, Y, W, H)
				WinMove, A,, X, Y, W/2, H
				return
				}
			if Mouse_X>0
				{
				splashimage,off
				goto,start
				}
			}
		}
	Win__GetDesktopPos(X,Y,Width,Height)	
	Width-=5
	if (width < mouse_x)
		{	;-----------------------------------------right
		detecthiddenwindows ,on
		splashimage,shade.jpg,hide b2
		WinSet, Transparent, 85, %A_ScriptName%
		Win__GetDesktopPos(X, Y, W, H)
		x:=x+3
		y:=y+3
		w:=w-6
		h:=h-6
		winmove,%A_ScriptName%,, X + W/2, Y, W/2, H
		sleep 10
		SplashImage, Show, b2,,, SplashImage
		loop
			{
			sleep 50
			coordmode,mouse,screen
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				WinGetActiveStats,Title,Width,Height,X,Y
				winget,ID,ID,%Title%
				check:=%id%check
				if check=1
					{
					goto,skipright
					}
				%ID%check=1
				%ID%Width=%width%
				%ID%Height=%height%
				%ID%x=%x%
				ID=
				skipright:
				splashimage,off
				Win__GetDesktopPos(X, Y, W, H)
				winMove, A,, X + W/2, Y, W/2, H
				return
				}
			Win__GetDesktopPos(X,Y,Width,Height)	
			Width-=5
			if (width > mouse_x)
				{
				splashimage,off
				goto,start
				}
			}
		}
	if mouse_y=0
		{	;-----------------------------------------full
		detecthiddenwindows ,on
		splashimage,shade.jpg,hide b2
		WinSet, Transparent, 85, %A_ScriptName%
		Win__GetDesktopPos(X, Y, W, H)
		x:=x+4
		y:=y+4
		w:=w-7
		h:=h-7
		winmove,%A_ScriptName%,,X, Y, W, H
		sleep 10
		SplashImage, Show, b2,,, SplashImage
		loop
			{
			sleep 50
			coordmode,mouse,screen
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				WinGetActiveStats,Title,Width,Height,X,Y
				winget,ID,ID,%Title%
				check:=%id%check
				if check=1
					{
					goto,skipfull
					}
				%ID%check=1
				%ID%Width=%width%
				%ID%Height=%height%
				%ID%x=%x%
				ID=
				skipfull:
				splashimage,off
				Win__GetDesktopPos(X, Y, W, H)
				winMove, A,, X, Y, W, H
				return
				}
			if mouse_y>3
				{
				splashimage,off
				goto,start
				}
			}
		}
	WinGetActiveStats,Title,Width,Height,X,Y
	winget,ID,ID,%Title%
	check:=%id%check
	if check=1
		{
		WinGetActiveStats,Title,Width,Height,X,Y
		winget,ID,ID,%Title%
		Originalwidth:=%ID%Width
		Originalheight:=%ID%height
		%ID%check=
		%ID%Width=
		%ID%height=
		WinGetActiveStats,ActiveTitle,total,CurrentHeight,p,p
		coordmode,mouse,relative
		MouseGetPos,given
		Calc:= given / total
		Calc:= Calc*100
		Calc:= Calc / 100
		Calc:= Calc*originalwidth
		coordmode,mouse,screen
		MouseGetPos,mouse_x
		Win__GetDesktopPos(X,Y,Width,Height) 
		Calc2:= width-mouse_x
		Calc2:= Calc2+Calc
		Calc2:= width-Calc2
		Calc:=Calc2+originalwidth
		coordmode,mouse,screen
		MouseGetPos,mouse
		Calc:=Calc-mouse
		mouse:=mouse-Calc2
		mouse1:=23-mouse
		if mouse<23
			{
			Calc2:=Calc2-mouse1
			}
		if Calc<75
			{
			Calc:=80-Calc
			Calc2:=Calc2+Calc
			}		
		winmove,%ActiveTitle%,,%Calc2%,,%originalwidth%,%originalheight%
		ID=
		%ID%x=
		goto,start
		}
	If (GetKeyState("LButton","P")=0)
		{
		return
		}
	goto,start
	}
Return

;--------------------------------------Shortcut keys

#right::Win__HalfRight()
#left::Win__HalfLeft()
#up::Win__FullSize()


gwarble
  • Members
  • 624 posts
  • Last active: Aug 12 2016 07:49 PM
  • Joined: 23 May 2009
very nice work man

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
I also thought of another feature I would like to add. In windows 7 if you stretch a window to the top of the screen, it will stretch it to the bottom too. So I will probably do that too. I am also rewriting my code alot cleaning it up and simplifying it.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Well i finally have the centering and resizing features identical to the way windows 7 handles it. I am just finishing the preview for window stretching to the top or bottom. Then it should be 100% done.

lorenzodow
  • Members
  • 2 posts
  • Last active: Aug 26 2010 11:14 PM
  • Joined: 26 Aug 2010
This is really cool. Made my day...after I figured out what authotkey was and downloaded it and was able to test the script. One of my machines is win 7 now, and working on the xp machine has been driving me crazy without this functionality. A google search brought me here.. Thanks for all the hard work.

Just wondering. In Win 7, # with the down arrow minimizes the window. Didn't see that here..

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008

Just wondering. In Win 7, # with the down arrow minimizes the window. Didn't see that here..

Thats simple:
#Down::WinMinimize, A

aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

lorenzodow
  • Members
  • 2 posts
  • Last active: Aug 26 2010 11:14 PM
  • Joined: 26 Aug 2010
Yes, I wold say that was easy! Thanks.

I told you I was a newb :-)

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
K I inserted that into the code. Simple ad. I am almost done with the aero stretch snap feature. Then I had another idea that isnt in windows 7. I'll give you more details after I finish what I mentioned first.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Here is the latest, with every function that I know of in windows 7 Aero Snap:


#Persistent
detecthiddenwindows ,on

;---------------------------detects closing windows / clears old data

SetBatchLines, -1
Process, Priority,, High
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam )
	{
	Global ID
	If ( wParam = 2 ) 
		{
		SetFormat, Integer, Hex
		ID := lParam + 0
		SetFormat, Integer, D
		SetTimer, MyRoutine, -1
		}
	}

MyRoutine:
if %ID%check=1
	{
	%ID%check=
	%ID%width=
	%ID%height=
	%ID%X=
	}
Return



;--------------------------------------------handles Preview

Win__SplashSet()
{
splashimage,shade2243324.jpg,hide b2
WinSet, Transparent, 85, %A_ScriptName%
x+=3
y+=3
w-=6
h-=6
}

;--------------------------handles checking/storing window information

Win__GetIDInformation(ByRef ID, ByRef Width, ByRef Height)
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skip
	}
skip:
sleep 5
}

;-----------------------------------------handles desktop variables

Win__GetDesktopPos(ByRef X, ByRef Y, ByRef W, ByRef H)
{
X := 0
Y := 0
SysGet, MonitorWorkArea, MonitorWorkArea
W:=A_ScreenWidth-2
H=%MonitorWorkAreaBottom%
}

;----------------------------------------handles left half maximize 

Win__HalfLeft()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipsave1
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
%ID%x=%x%
ID=
skipsave1:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W/2, H
return
}


;----------------------------------------handles right half maximize

Win__HalfRight()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipsave2
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
%ID%x=%x%
ID=
skipsave2:
Win__GetDesktopPos(X, Y, W, H)
winMove, A,, X + W/2, Y, W/2, H
return
}

;----------------------------------------handles full maximize 

Win__FullSize()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
	{
	goto,skipsave3
	}
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
%ID%x=%x%
ID=
skipsave3:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W, H
return
}

;-----------------------detects when window is being dragged

*~LButton::
CoordMode, Mouse, Screen
MouseGetPos, x, y, hwnd
SendMessage, 0x84, 0, (x&0xFFFF) | (y&0xFFFF) << 16,, ahk_id %hwnd%
RegExMatch("ERROR TRANSPARENT NOWHERE CLIENT CAPTION SYSMENU SIZE MENU HSCROLL VSCROLL MINBUTTON MAXBUTTON LEFT RIGHT TOP TOPLEFT TOPRIGHT BOTTOM BOTTOMLEFT BOTTOMRIGHT BORDER OBJECT CLOSE HELP", "(?:\w+\s+){" . ErrorLevel+2&0xFFFFFFFF . "}(?<AREA>\w+\b)", HT)
if htarea!=TOP
	{
	}
else
	{
	WinGetActiveStats,Title,Width,Height,X,Y
	winget,ID,ID,%Title%
	check:=%id%check
	if check=1
		{
		goto,skiptop
		}
	%ID%check=1
	%ID%Width=%width%
	%ID%Height=%height%
	%ID%x=%x%
	skiptop:
	loop
		{
		sleep 5
		coordmode,mouse,screen
		MouseGetPos,Mouse_X,Mouse_Y
		if (mouse_y=0)
			{
			Win__GetDesktopPos(X, Y, W, H)
			Win__SplashSet()
			wingetactivestats,Title,W,H2,x,Y
			height:=h-h2-y
			winmove,%A_ScriptName%,,X,Y+H2,W,height
			SplashImage, Show, b2,,, SplashImage
			loop
				{
				sleep 5
				coordmode,mouse,screen
				MouseGetPos,Mouse_X,Mouse_Y
				if (mouse_y>0)
					{
					splashimage,off
					goto,skiptop
					}
				If (GetKeyState("LButton","P")=0)
					{
					splashimage,off
					Win__GetDesktopPos(X, Y, W, H)
					winMove,A,,,0,, H
					return
					}
				}
			}
		If (GetKeyState("LButton","P")=0)
			{
			%ID%check=
			%ID%Width=
			%ID%Height=
			%ID%x=
			return
			}
		}
	}
if htarea!=BOTTOM
	{
	}
else
	{
	WinGetActiveStats,Title,Width,Height,X,Y
	winget,ID,ID,%Title%
	check:=%id%check
	if check=1
		{
		goto,skipbottom
		}
	%ID%check=1
	%ID%Width=%width%
	%ID%Height=%height%
	%ID%x=%x%
	skipbottom:
	loop
		{
		sleep 5
		coordmode,mouse,screen
		MouseGetPos,Mouse_X,Mouse_Y
		Win__GetDesktopPos(X, Y, W, H)
		check:=H-mouse_y-1
		if (check<3)
			{
			Win__GetDesktopPos(X, Y, W, H)
			Win__SplashSet()
			wingetactivestats,Title,W,H,x,Y
			winmove,%A_ScriptName%,,X,0,W,Y
			SplashImage, Show, b2,,, SplashImage
			loop
				{
				sleep 5
				coordmode,mouse,screen
				MouseGetPos,Mouse_X,Mouse_Y
				Win__GetDesktopPos(X, Y, W, H)
				check:=H-mouse_y-1
				if (check>3)
					{
					splashimage,off
					goto,skipbottom
					}
				If (GetKeyState("LButton","P")=0)
					{
					splashimage,off
					Win__GetDesktopPos(X, Y, W, H)
					winMove,A,,,0,, H
					return
					}
				}
			}
		If (GetKeyState("LButton","P")=0)
			{
			%ID%check=
			%ID%Width=
			%ID%Height=
			%ID%x=
			return
			}
		}
	}
if htarea!=CAPTION
	{
	Return
	}
 MouseGetPos,_x,_y
 While GetKeyState("LButton","P") && x=_x && y=_y
	{
	start:
	sleep 5
	wingetactivestats,ActiveTitle,Width,Height,x,Y
	winget,test,MinMax,%activetitle%
	if test=1
		{
		return
		}
	coordmode,mouse,screen
	MouseGetPos,Mouse_X,Mouse_Y
	if Mouse_X=0
		{
		Win__GetDesktopPos(X, Y, W, H)
		Win__SplashSet()
		winmove,%A_ScriptName%,,x,y,w/2,h
		SplashImage, Show, b2,,, SplashImage
		loop
			{
			sleep 5
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				Win__GetIDInformation(ID,Width,Height)
				%ID%check=1
				%ID%Width=%width%
				%ID%Height=%height%
				ID=
				splashimage,off
				Win__GetDesktopPos(X, Y, W, H)
				WinMove, A,, X, Y, W/2, H
				return
				}
			if Mouse_X>0
				{
				splashimage,off
				goto,start
				}
			}
		}
	Win__GetDesktopPos(X,Y,Width,Height)	
	Width-=5
	if (width < mouse_x)
		{
		Win__GetDesktopPos(X, Y, W, H)
		Win__SplashSet()
		winmove,%A_ScriptName%,, X + W/2, Y, W/2, H
		SplashImage, Show, b2,,, SplashImage
		loop
			{
			sleep 5
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				Win__GetIDInformation(ID,Width,Height)
				%ID%check=1
				%ID%Width=%width%
				%ID%Height=%height%
				ID=
				splashimage,off
				Win__GetDesktopPos(X, Y, W, H)
				winMove, A,, X + W/2, Y, W/2, H
				return
				}
			Win__GetDesktopPos(X,Y,Width,Height)	
			Width-=5
			if (width > mouse_x)
				{
				splashimage,off
				goto,start
				}
			}
		}
	if mouse_y=0
		{
		Win__GetDesktopPos(X, Y, W, H)
		Win__SplashSet()
		winmove,%A_ScriptName%,,X, Y, W, H
		SplashImage, Show, b2,,, SplashImage
		loop
			{
			sleep 5
			MouseGetPos,Mouse_X,Mouse_Y
			If (GetKeyState("LButton","P")=0)
				{
				Win__GetIDInformation(ID,Width,Height)
				%ID%check=1
				%ID%Width=%width%
				%ID%Height=%height%
				ID=
				splashimage,off
				Win__GetDesktopPos(X, Y, W, H)
				winMove, A,, X, Y, W, H
				return
				}
			if mouse_y>3
				{
				splashimage,off
				goto,start
				}
			}
		}
	WinGetActiveStats,Title,Width,Height,X,Y
	winget,ID,ID,%Title%
	check:=%id%check
	if check=1
		{
		WinGetActiveStats,Current_Title,Current_Width,Current_Height,Current_X,Y
		Win__GetDesktopPos(X,Y,Width,Height) 
		MouseGetPos,Mouse_Screen
		winget,ID,ID,%current_Title%
		Original_width:=%ID%Width
		Original_height:=%ID%height
		%ID%check=
		%ID%Width=
		%ID%height=
		coordmode,mouse,relative
		MouseGetPos,Mouse_Window
		check:=current_width/2
		if (mouse_window<check)
			{
			;(left side)
			check:=original_width/2
			if (mouse_window<check)
				{
				if (mouse_window>original_width-75)
					{
					;(Center the window left)
					x:=mouse_screen-(original_width/2)
					}
				else
					{
					;(align left side)
					x:=current_x
					}
				goto,end
				}
			}
		check:=current_x+Current_width-Original_width+(original_width/2)
		if (check<mouse_screen)
			{
			;(align right side)
			x:=current_x+Current_width-Original_width
			goto,end
			}
		if (Mouse_Window<Current_width-75)
			{
			;(center the window right)
			x:=mouse_screen-(original_width/2)
			goto,end
			}
		end:
		winmove,%Current_Title%,,%x%,,%original_width%,%original_height%
		ID=
		x=
		goto,start
		}
	If (GetKeyState("LButton","P")=0)
		{
		return
		}
	goto,start
	}
Return

;--------------------------------------Shortcut keys

#right::Win__HalfRight()

#left::Win__HalfLeft()

#up::Win__FullSize()

#Down::WinMinimize, A


kanngard
  • Members
  • 1 posts
  • Last active: Oct 25 2010 05:14 AM
  • Joined: 25 Oct 2010

Here is the latest, with every function that I know of in windows 7 Aero Snap:


Win+Shift+Left and Win+Shift+Right doesn't work to move the window to the next / previous monitor. Using your script works on one monitor, but trying to move a window manually to the second monitor fails since the window "snaps" to either the left or the right of the first monitor.

Keep up the good work guys!