AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Select the position and size of windows, with preview

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Tue Aug 01, 2006 2:31 am    Post subject: Select the position and size of windows, with preview Reply with quote

GroupBoxes are highlighted if they are of style 0x1000. Their title text is left justified in style 0x1100, otherwise it is centered on the top edge. This feature allows dynamic changing of the GUI, like when some GroupBoxes represent window positions, the current selection can be shown.

The following script allows choosing the size and position of the active window from a number of predetermined ones. When Win-W is pressed a little GUI window pops up, with the outline of all the possible window positions. It remains on screen until the Win key is released. When this GUI is visible, pressing the keys 0,1…7 highlights the corresponding window position in the GUI. Pressing a new digit changes the highlight. When the Win key is finally released, the last selected position and size is assigned to the active window. Esc cancels the process, without changing the foreground window.
Code:
SysGet m, MonitorWorkArea
mW := mRight-mLeft
mH := mBottom-mTop
mX := mW//4
mY := mH//5
mA := mW//10
mB := mH//10

#w::
   WinGet ID, ID, A
   A = ahk_ID %ID%
   Gui Add, GroupBox, x10  y05  w400 h300, 0
   Gui Add, GroupBox, x25  y20  w300 h240, 1
   Gui Add, GroupBox, x95  y20  w300 h240, 2
   Gui Add, GroupBox, x25  y50  w300 h240, 4
   Gui Add, GroupBox, x95  y50  w300 h240, 3
   Gui Add, GroupBox, x70  y70  w280 h170, 5
   Gui Add, GroupBox, x88  y88  w244 h144, 6
   Gui Add, GroupBox, x106 y106 w208 h118, 7
   Gui +AlwaysOnTop -Caption +Border
   Gui Show

   Postn =
   Loop {
      Loop 8
         If GetKeyState(A_Index-1,"P") {
            GuiControl -0x1100,%Postn%     ; Remove highlight of last GroupBox
            GuiControl  hide,  %Postn%
            GuiControl  show,  %Postn%     ; Redraw last GroupBox
            Postn := A_Index-1             ; New selection
            GuiControl +0x1100,%Postn%     ; Highlight new GroupBox
         }
      If !GetKeyState("LWin","P")          ; Repeat while LWin is pressed
         Break
      If GetKeyState("Esc","P") {          ; Cancel
         Gui Destroy
         Return
      }
      Sleep 10                             ; Give time for others
   }
   Gui Destroy                             ; Close position-selecting GUI

   IfEqual Postn,0, WinMaximize %A%
   Else {
      WinGet MM, MinMax, %A%
      IfEqual MM,1, WinRestore %A%         ; Moved a maximized window behaves as maximized
      IfEqual      Postn,1, WinMove %A%,, mLeft,    mTop,    mW-mX, mH-mY
      Else IfEqual Postn,2, WinMove %A%,, mLeft+mX, mTop,    mW-mX, mH-mY
      Else IfEqual Postn,3, WinMove %A%,, mLeft+mX, mTop+mY, mW-mX, mH-mY
      Else IfEqual Postn,4, WinMove %A%,, mLeft,    mTop+mY, mW-mX, mH-mY

      Else IfEqual Postn,5, WinMove %A%,, mLeft+mA,   mTop+mB,   mW-mA*2, mH-mB*2
      Else IfEqual Postn,6, WinMove %A%,, mLeft+mA*2, mTop+mB*2, mW-mA*4, mH-mB*4
      Else IfEqual Postn,7, WinMove %A%,, mLeft+mA*3, mTop+mB*3, mW-mA*6, mH-mB*6
   }
Return
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5887

PostPosted: Tue Aug 01, 2006 6:32 am    Post subject: Reply with quote

Very nice utility Mr.Laszlo!
Just 56 lines! Shocked... If I had tried, it would have been 200+.

Thanks for sharing. It will be very helpful for me.

Regards, Smile
_________________
SKAN - Suresh Kumar A N
Back to top
View user's profile Send private message
Eleria



Joined: 09 May 2006
Posts: 92

PostPosted: Tue Aug 01, 2006 8:54 am    Post subject: Reply with quote

Utterly amazing Laszlo...
Though the script itself is not complicated, you did get the idea and thats great ^_^
_________________


Looking for a game/anime ost?
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Tue Aug 01, 2006 9:04 am    Post subject: Reply with quote

Wonderful! I liked the way you used the GroupBoxes and Buttons together.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
vogg
Guest





PostPosted: Sun Aug 06, 2006 10:13 am    Post subject: Reply with quote

That's really nice!
Back to top
nick
Guest





PostPosted: Tue Aug 08, 2006 11:28 am    Post subject: Reply with quote

Here's the pic.
Back to top
_adam
Guest





PostPosted: Fri Mar 21, 2008 6:41 pm    Post subject: Reply with quote

wow, that's nice. a bigger/clearer preview would be nice. I've been looking for a window move/resize script/s and I'm getting a lot of ideas here for personal use.

thanks laszlo. beautiful script.
Back to top
Azerty



Joined: 19 Dec 2006
Posts: 72
Location: France

PostPosted: Fri Mar 21, 2008 11:32 pm    Post subject: Reply with quote

Hi Laszlo

Nice one. Would be nicer though combined with iason's positioning

If anyone has time to mix-match, it would be great
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Sat Mar 22, 2008 12:10 am    Post subject: Reply with quote

How should it work, then?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group