AutoHotkey Community

It is currently May 24th, 2012, 1:55 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: December 4th, 2007, 8:21 pm 
Ever had the annoying problem of windows not showing up in the desktop area or hanging off of the edge of the screen? This script is especially useful for those situations that can occur if you physically change your monitor setup, screen resolution, or Alt-Tab out from a game.

This script simply requires two mouse clicks to define a box. The first click defines the upper-left corner and the second defines the lower-right corner. All windows hanging out of or not located in this region are moved and resized to fit into the user-defined box.

Code:
#SingleInstance Force   ;Allow only single instance

;Use these variables to check for reasonable settings later
ReasonableWidth:=200
ReasonableHeight:=200

KeyWait LButton,T0.5   ;don't capture the mouse click that started the script

;Get upper-left corner of screen
ToolTip Select Upper-Left Corner of active screen.
KeyWait LButton,D T10
if ErrorLevel = 1  ;timed out
    ExitApp
CoordMode Mouse,Screen
MouseGetPos UpperLeftX,UpperLeftY
ToolTip

KeyWait LButton,T0.5   ;wait for the mouse button to be released or 0.5 seconds

;Get lower-right corner of screen
ToolTip Select Lower-Right Corner of active screen.
KeyWait LButton,D T10
if ErrorLevel = 1  ;timed out
    ExitApp
CoordMode Mouse,Screen
MouseGetPos LowerRightX,LowerRightY
ToolTip

MaxWidth := LowerRightX - UpperLeftX
MaxHeight := LowerRightY - UpperLeftY

;Check for reasonable values
if(MaxWidth < ReasonableWidth)
   MaxWidth := ReasonableWidth

if(MaxHeight < ReasonableHeight)
   MaxHeight := ReasonableHeight


WinGet, id, List
Loop, %id%
{
    if (A_Index > 1)
    {
        this_id := id%A_Index%                ;for this iteration of the loop
        WinGetPos x,y,width,height,ahk_id %this_id%
        if (width <> 0) AND (height <> 0)
        {
            if (width > MaxWidth)
                width := MaxWidth
            if (height > MaxHeight)
                height := MaxHeight
            if (x < UpperLeftX) OR (x > LowerRightX)
                x := UpperLeftX
            if (y < UpperLeftY) OR (y > LowerRightY)
                y := UpperLeftY
            if ( (x+width) > MaxWidth)
                x := UpperLeftX
            if ( (y+height) > MaxHeight)
                y := UpperLeftY
            WinMove ahk_id %this_id%,,%x%,%y%,%width%,%height%
        }
    }
}
ExitApp

Esc::               ;Esc aborts the user-defined box entry
    ExitApp



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2007, 4:30 am 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
this looks like a good script but i would like to suggest that upper-left & bottom-right co-ordinates are saved into an INI file so that there is no need to set them every time. i also noticed that windows opened after the script is not automatically re-aligned, the "persistent" feature would be nice.

thanks & i hope you will consider my requests.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: cmulcahy, Exabot [Bot], Google [Bot], MSN [Bot], tomoe_uehara and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group