Jump to content
Sign in to follow this  
W2lkm2n

Window floater

Recommended Posts

W2lkm2n

This will "float" windows defined in $WINDOWS array to the left edge of the screen like this:

post-75150-0-84208200-1358573105_thumb.p

If you hover the mouse over the desired window's edge, it will float in, and you can use it. If you move the mouse out of the window area, it will float back.

If you exit the script, the windows will restore their original positions.

If the sum of the window heights would exceed the Desktop height, nothing will happen to the windows which wouldn't fit.

You can resize, close and open windows, they will jump to the desired position, but you have to move the mose there in that case.

#include <Constants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
_Singleton(@ScriptName)

; window titles here
Const $WINDOWS[3] = ['[CLASS:CalcFrame]', '[CLASS:HH Parent]', '[CLASS:Notepad]']
Const $MARGIN = 20

OnAutoItExitRegister("RestoreWindows")

Global $iWinCount, $aOriginalPositions[1]
For $iWinCount = 0 To UBound($WINDOWS) - 1
ReDim $aOriginalPositions[$iWinCount + 1]
$aOriginalPositions[$iWinCount] = WinGetPos($WINDOWS[$iWinCount])
Next

While 1
For $sWindow In $WINDOWS
MoveWindow($sWindow)
Next
Sleep(50)
WEnd

Func MoveWindow($sWinTitle)
Local $iY = CalculateYPos($sWinTitle)
If $iY > @DesktopHeight Then Return

Local $hWnd = WinGetHandle($sWinTitle)
If @error Then Return

Local $aWinPos = WinGetPos($hWnd)
If $aWinPos = 0 Then Return

Local $aMousePos = MouseGetPos()

If $aMousePos[0] <= $MARGIN And _
($aMousePos[1] >= $iY And $aMousePos[1] <= ($iY + $aWinPos[3])) And _
$aWinPos[0] < 0 Then
_WinAPI_SetWindowPos($hWnd, $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_NOMOVE, $SWP_NOSIZE))
WinMove($hWnd, '', 0, $iY, $aWinPos[2], $aWinPos[3], 2)
ElseIf ($aWinPos[0] >= 0) And ($aMousePos[0] > $aWinPos[2] + $MARGIN Or _
($aMousePos[1] < $iY - $MARGIN Or $aMousePos[1] > ($iY + $aWinPos[3] + $MARGIN))) Then
WinMove($hWnd, '', -$aWinPos[2] + 10, $iY, $aWinPos[2], $aWinPos[3], 2)
EndIf
EndFunc   ;==>MoveWindow

Func CalculateYPos($sWinTitle)
Local $iY = 0, $aPos
For $sWindow In $WINDOWS
If $sWindow = $sWinTitle Then ExitLoop
$aPos = WinGetPos($sWindow)
If Not @error Then $iY = $iY + $aPos[3]
Next
Return $iY
EndFunc   ;==>CalculateYPos

Func RestoreWindows()
Local $i, $aPos
For $i = 0 To UBound($WINDOWS) - 1
$aPos = $aOriginalPositions[$i]
If WinExists($WINDOWS[$i]) Then WinMove($WINDOWS[$i], '', $aPos[0], $aPos[1])
Next
EndFunc   ;==>RestoreWindows

Any advice appreciated!

  • Like 1

Share this post


Link to post
Share on other sites
spudw2k
Mat

It would cool if this could be activated by dragging a window to an edge, and then de-activated by moving it away. Probably a little tricky to do that nicely for other windows though. Would have to have some way of preventing aero snap as well.

Doesn't deal with multiple monitors either.

I'd also have some kind of focus setting, where a window isn't rolled back to hidden while it has focus. I tend to move the mouse away when I'm typing, which makes this not so useful for notepad.

Turn this into a full program and it would be very cool though. And very useful :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×