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
bufferlow
  • Guests
  • Last active:
  • Joined: --
Hi PatrickS,

I just came by looking for a way to auto align the many explorer windows I use every day. For now I have "only" used the auto grid arrangement on my laptop with 4 explorer windows for testing but this is just what I was looking for :p

Can't wait to use it on my multi monitor workstation.

It's a YAY great work! Thank you!
bufferlow

PatrickS
  • Members
  • 14 posts
  • Last active: Jul 20 2019 01:08 AM
  • Joined: 21 Mar 2010
Hey butterlow

Great to see someone using it. There hasn't been a lot of response on the thread to that particular enhancement (as in, zero), so I'm glad you're finding it useful.

Let me know how you end up using / configuring it.

Cheers,
Patrick

berban
  • Members
  • 202 posts
  • Last active: Apr 12 2019 01:08 AM
  • Joined: 30 Dec 2009
hey patrick, I actually have windows 7 but I implemented something like this for it anyway - in order to use for kde windowing <!-- m -->http://www.autohotke...c58291.html<!-- m --> at the bottom and prefixed with "KDE_"... nice coding man and keep it up

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
and one more thing... in regard to your latest post, I've spent a bunch of time writing in ahk and I've posted some of them online, and yeah no one really uses them most of the time :cry: but it's ok because honestly I use them enough to justify the time I spent making them! that's what's great about ahk... it's probably easier to make exactly what you want than it is to find it online.
Also, to make sure people can find your scripts, you can post them on the wiki http://www.autohotkey.com/wiki. I'm not sure if people actually check that either, but at least that way it's legit.

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!


Nonregistered
  • Guests
  • Last active:
  • Joined: --
Works lika a charm. Thanks!

tomte
  • Members
  • 12 posts
  • Last active: Aug 07 2011 09:02 PM
  • Joined: 12 Aug 2007
Yet another version - based on the code in PatrickS first post but added functionality to remember the previous position for the window to restore with #Down.
Pressing #Down a second time also minimizes the window like on Win7.


;======================================== WIN+Left/Right ========================================
; http://www.autohotkey.com/forum/topic55951.html ....modified to remember old position for each window
;; -----------------------------------------------------------------------
; Get the position and size of the desktop, taking the taskbar area into account.
; This function probably doesn't work on secondary monitors.

Win__GetDesktopPos(ByRef X, ByRef Y, ByRef W, ByRef H) {
	WinGetPos, TrayX, TrayY, TrayW, TrayH, ahk_class Shell_TrayWnd   ; Get dimensions of the system tray (taskbar)
	X := 0
	Y := TrayY ? 0 : TrayH
	W := A_ScreenWidth
	H := A_ScreenHeight - TrayH
}

Win__SavePos() {
	local class, winY	; makes win?_%class% variables below global, to remember old window positions
	WinGetClass, class, A
	WinGetPos,, winY,,, A
	if (winY != 0)		; don't save if window at top of screen (maximized or moved there by #Left/Right)
		WinGetPos, winX_%class%, winY_%class%, winW_%class%, winH_%class%, A
}

Win__HalfLeft() {
	Win__SavePos()
	Win__GetDesktopPos(X, Y, W, H)
	WinMove, A,, X, Y, W/2, H
}

Win__HalfRight() {   
	Win__SavePos()
	Win__GetDesktopPos(X, Y, W, H)
	WinMove, A,, X + W/2, Y, W/2, H
}

Win__FullSize() {   
	Win__SavePos()
	Win__GetDesktopPos(X, Y, W, H)
	WinMove, A,, X, Y, W, H
}

Win__Center() {
	WinGetClass, class, A
	Win__GetDesktopPos(X, Y, W, H)
	WinGetPos, winX, winY, winW, winH, A
	If ((winX == winX_%class% and winY == winY_%class% and winW == winW_%class% and winH == winH_%class%) or (winX == X + W//5 and winY == Y + H//8 and winW == W - W//2.5 and winH == H - H//4))
		WinMinimize, A
	Else If (winX_%class%)
		WinMove, A,, winX_%class%, winY_%class%, winW_%class%, winH_%class%	; restore old position
	Else
		WinMove, A,, X + W//5, Y + H//8, W - W//2.5, H - H//4	; nothing saved - center window
}
#Left::   Win__HalfLeft()
#Right::  Win__HalfRight()
#Up::     Win__FullSize()
#Down::   Win__Center()


ludamo
  • Members
  • 13 posts
  • Last active: Jan 29 2015 08:36 AM
  • Joined: 12 Jul 2008
Have just finished writing some of my own dual monitor, window management code for XP and came looking for possible AutoHotkey solutions for the Windows 7 window drag and tiling placement feature.
In looking at the code here I noticed that you haven't used some inbuilt Windows functions (which I discovered in the forum) which may make your coding easier. i.e.
DllCall("GetCursorPos", "Int64P", pt)
hMonitor := DllCall("MonitorFromPoint", "Int64", pt, "UInt", 2)
DllCall("MonitorFromWindow", "UInt", win_id, "UInt", 2)

Also after looking for ages I came across this function in the forum: DllCall("GetAltTabInfoA", "UInt", hAltTab, "Int", -1, "UInt", &ATI, "UInt", 0, "UInt", 0), which simplified a function I made to push down the top window on a particular monitor and activate the window below (instead of rushing back to the task bar on the primary monitor all the time to switch windows on that display). I would naturally be happy to post the code if anyone is interested.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Hey love the script! I just though it needs one more thing, in windows 7 you can drag a window to the left or right or up to do these functions so I added that in, its pretty simple but it works as far as I know, I tested it on on my virtual machine running xp.

#NoEnv

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

Win__HalfLeft()
	{
	count+=1

	Win__GetDesktopPos(X, Y, W, H)
	WinMove, A,, X, Y, W/2, H
	}

Win__HalfRight()
	{   
	Win__GetDesktopPos(X, Y, W, H)
	winMove, A,, X + W/2, Y, W/2, H
	}

Win__FullSize()
	{   
	Win__GetDesktopPos(X, Y, W, H)
	WinMove, A,, X, Y, W, H
	}


*~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 ;Wait until user begins dragging
	MouseGetPos,_x,_y
    While GetKeyState("LButton","P") ;Show ToolTip while dragging
	{
	keywait,lbutton
	coordmode,mouse,screen
	MouseGetPos,Mouse_X,Mouse_Y
	if Mouse_X=0
		{
		Win__HalfLeft()
		}
	Win__GetDesktopPos(X,Y,Width,Height)	
	Width-=2
	Mouse_X-=Width
	if mouse_x=0
		{
		Win__HalfRight()
		}
	if mouse_y=0
		{
		Win__FullSize()
		}
	}
Return

~^s::
sleep 100
reload


KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
im currently trying to figure out a way that when you move a window that was resized by this function that it will go back to its original size, but not position.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Ok as far as I know this version should be compatible with just about any screen size, I was having issues with that. If anyone is reading this thread can you give this a try on windows xp and let me know if it works for you.

Features:
3 hotkeys that do the window half maximize for the left and right side and a windows maximize.
Win+left
Win+right
Win+up

The same 3 functions can also be done by dragging the window to the corresponding edge on your screen. (This is what I added to the script)

Heres the code:
#NoEnv

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

Win__HalfLeft()
   {
   count+=1

   Win__GetDesktopPos(X, Y, W, H)
   WinMove, A,, X, Y, W/2, H
   }

Win__HalfRight()
   {   
   Win__GetDesktopPos(X, Y, W, H)
   winMove, A,, X + W/2, Y, W/2, H
   }

Win__FullSize()
   {   
   Win__GetDesktopPos(X, Y, W, H)
   WinMove, A,, X, Y, W, H
   }


*~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 ;Wait until user begins dragging
      MouseGetPos,_x,_y
    While GetKeyState("LButton","P") ;Show ToolTip while dragging
   {
   keywait,lbutton
   coordmode,mouse,screen
   MouseGetPos,Mouse_X,Mouse_Y
   if Mouse_X=0
      {
      Win__HalfLeft()
      }
   Win__GetDesktopPos(X,Y,Width,Height)   
   Width-=5
   if (width < mouse_x)
      {
      Win__HalfRight()
      }
   if mouse_y=0
      {
      Win__FullSize()
      }
   }
Return

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


vahju
  • Members
  • 337 posts
  • Last active: Sep 21 2014 03:52 AM
  • Joined: 17 Feb 2008
Hey KooKsTeR that is some good coding.

Dragging seems to work fine but for some reason the window left key is not working. Windows right works and so does windows up.

Window is maxed cannot use window left.
Window is maxed then I used window right. Moves window to right. Then use window left and it returns window to original position. I thought this would move the window to left side of the screen.

Keep up the good work.

Tested this on WinXP sp3 with lastest version of ahk.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
LOL HAHAHAHAHA OMG its a stupid typo error! Thanks for the report, heres the fix:


#NoEnv

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

Win__HalfLeft()
   {
   count+=1

   Win__GetDesktopPos(X, Y, W, H)
   WinMove, A,, X, Y, W/2, H
   }

Win__HalfRight()
   {   
   Win__GetDesktopPos(X, Y, W, H)
   winMove, A,, X + W/2, Y, W/2, H
   }

Win__FullSize()
   {   
   Win__GetDesktopPos(X, Y, W, H)
   WinMove, A,, X, Y, W, H
   }


*~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 ;Wait until user begins dragging
      MouseGetPos,_x,_y
    While GetKeyState("LButton","P") ;Show ToolTip while dragging
   {
   keywait,lbutton
   coordmode,mouse,screen
   MouseGetPos,Mouse_X,Mouse_Y
   if Mouse_X=0
      {
      Win__HalfLeft()
      }
   Win__GetDesktopPos(X,Y,Width,Height)   
   Width-=5
   if (width < mouse_x)
      {
      Win__HalfRight()
      }
   if mouse_y=0
      {
      Win__FullSize()
      }
   }
Return

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


vahju
  • Members
  • 337 posts
  • Last active: Sep 21 2014 03:52 AM
  • Joined: 17 Feb 2008
KooKsTeR your latest code works great. Thanks for fix.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Glad someone likes it. Now the next hurdle having it remember original window size. I think i am going to have to set up an array for that. Havent used those before.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Ok so I suck at arrays, but I found a way by storing any windows information that is altered. So for example, I drag a window to the right side, it stores the windows information in a text file called after it. Also everytime you drag a window it will get that windows title and check to see if there is a file named after it if there is it will read it and set the windows size according to the file. The only way there is a file though is if you dragged it to one of the sides.

It works pretty well as far as i can tell. There is only two problems i can see happening, that is if a windows title changes, the file will not longer be associated with it. Or if the window title is too long. Anyone have an idea how to get around this?
#NoEnv

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

Win__HalfLeft()
	{
	wingetactivestats,Title,Width,Height,x,Y
	ifexist,%title%.txt
		{
		goto,skipleft
		}
	fileappend,
(
%width%
%height%
),%title%.txt
	skipleft:
	Win__GetDesktopPos(X, Y, W, H)
	WinMove, A,, X, Y, W/2, H
	}

Win__HalfRight()
	{
	wingetactivestats,Title,Width,Height,x,Y
	ifexist,%title%.txt
		{
		goto,skipright
		}
	fileappend,
(
%width%
%height%
),%title%.txt
	skipright:
	Win__GetDesktopPos(X, Y, W, H)
	winMove, A,, X + W/2, Y, W/2, H
	}

Win__FullSize()
	{
	wingetactivestats,Title,Width,Height,x,Y
	wingetactivestats,Title,Width,Height,x,Y
	ifexist,%title%.txt
		{
		goto,skipfull
		}
	fileappend,
(
%width%
%height%
),%title%.txt
	skipfull:
	Win__GetDesktopPos(X, Y, W, H)
	WinMove, A,, X, Y, W, H
	}


*~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 ;Wait until user begins dragging
		MouseGetPos,_x,_y
	 While GetKeyState("LButton","P") ;Show ToolTip while dragging
	{				;START DRAGGING CODE:
	keywait,lbutton
	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
		}
	wingetactivestats,Title,Width,Height,x,Y
	ifexist,%title%.txt
		{
		filereadline,width,%title%.txt,1
		filereadline,height,%title%.txt,2
		filedelete,%title%.txt
		winmove,%title%,,,,%width%,%height%
		return
		}		
	}
Return

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

~^s::
sleep 100
reload