Jump to content

Recommended Posts

Posted (edited)

Here is a function that allows your gui, or any window to be attached to the walls of your desktop.

; #FUNCTION# ====================================================================================================================
; Name...........: _GuiSnap
; Description ...: When the gui window is close the the desktop borders, it snaps the the sides, and corners.
; Syntax.........: _GuiSnap($aTitle[, $hText = ""[, $hDistance = 35[, $sXy = 4[, $TaskBar = 34]]]])
; Parameters ....: $aTitle      - The title of the window .
;                  $hText       - [optional]The text of the window.
;                  $hDistance   - [optional]The distance before the Gui snaps in pixels. Default = 35
;                  $sXy         - [optional]The x and y placement of the window. Default = 4
;                  $TaskBar     - [optional]The height of the task bar. Default = 34
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Bill Reithmeyer (billthecreator)
; Modified.......: 07.22.2008 9:07 AM
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GuiSnap($aTitle, $hText = "", $hDistance = 35, $sXy = 4, $TaskBar = 34)
    Local $wSize
    If $aTitle = "" Then
        SetError(1)
    Else
        $wSize = WinGetPos($aTitle)
        If $wSize[0] < $hDistance And $wSize[1] < $hDistance Then ; Top Left Hand Corner
            WinMove($aTitle, $hText, $sXy, $sXy)
        ElseIf $wSize[0] < $hDistance Then ; Left Side Of Desktop
            WinMove($aTitle, $hText, $sXy, $wSize[1])
        ElseIf $wSize[1] < $hDistance Then ; Top Of Desktop
            WinMove($aTitle, $hText, $wSize[0], $sXy)
        EndIf
        If $wSize[0] > @DesktopWidth - $hDistance - $wSize[2] And $wSize[1] < $hDistance Then ; Top Right Hand Corner
            WinMove($aTitle, $hText, @DesktopWidth - $sXy - $wSize[2], $sXy)
        ElseIf $wSize[0] > @DesktopWidth - $hDistance - $wSize[2] Then ; Right Side Of Desktop
            WinMove($aTitle, $hText, @DesktopWidth - $sXy - $wSize[2], $wSize[1])
        EndIf
        If $wSize[1] > @DesktopHeight - $hDistance - $TaskBar - $wSize[3] And $wSize[0] < $hDistance Then ; Bottom Left Hand Corner
            WinMove($aTitle, $hText, $sXy, @DesktopHeight - $TaskBar - $wSize[3])
        ElseIf $wSize[1] > @DesktopHeight - $hDistance - $TaskBar - $wSize[3] Then ; Bottom Of Desktop
            WinMove($aTitle, $hText, $wSize[0], @DesktopHeight - $TaskBar - $wSize[3])
        EndIf
        If $wSize[1] > @DesktopHeight - $hDistance - $TaskBar - $wSize[3] And $wSize[0] > @DesktopWidth - $hDistance - $wSize[2] Then ; Bottom Right Hand Corner
            WinMove($aTitle, $hText, @DesktopWidth - $sXy - $wSize[2], @DesktopHeight - $TaskBar - $wSize[3])
        EndIf
    EndIf
EndFunc   ;==>_GuiSnap
Edited by billthecreator

[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Posted (edited)

Good muttley , but i like this more: http://www.autoitscript.com/forum/index.ph...st&p=399062

An example-Script for yours, billthecreator:

#include <GUIConstants.au3>
$GUI = GUICreate('df')
GUISetState()
While 1
    _GuiSnap($GUI)
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

  billthecreator said:

Sorry, not quiet. here:

_GuiSnap("title", '', 35, 4, 34)

if you go look at my command prompt example, i have it in there.... be cautious though, its 1800 lines.

The example is right muttley You have made all parameters optional, so u don't have to use them, just put title as GUIHandle, then it works :)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

  • 5 years later...
Posted

#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
; #FUNCTION# ====================================================================================================================
; Name...........: _GuiSnap
; Description ...: When the gui window is close the the desktop borders, it snaps the the sides, and corners.
; Syntax.........: _GuiSnap($aTitle[, $hText = ""[, $hDistance = 35[, $sXy = 4[, $TaskBar = 34]]]])
; Parameters ....: $aTitle      - The title of the window .
;                  $hText       - [optional]The text of the window.
;                  $hDistance   - [optional]The distance before the Gui snaps in pixels. Default = 35
;                  $sXy         - [optional]The x and y placement of the window. Default = 4
;                  $TaskBar     - [optional]The height of the task bar. Default = 34
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Bill Reithmeyer (billthecreator)
; Modified.......: 07.22.2008 9:07 AM
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GuiSnap($aTitle, $hText = "", $hDistance = 35, $sXy = 4, $TaskBar = 34)
    Local $wSize
    If $aTitle = "" Then
        SetError(1)
    Else
        $wSize = WinGetPos($aTitle)
        If $wSize[0] < $hDistance And $wSize[1] < $hDistance Then ; Top Left Hand Corner
            WinMove($aTitle, $hText, $sXy, $sXy)
        ElseIf $wSize[0] < $hDistance Then ; Left Side Of Desktop
            WinMove($aTitle, $hText, $sXy, $wSize[1])
        ElseIf $wSize[1] < $hDistance Then ; Top Of Desktop
            WinMove($aTitle, $hText, $wSize[0], $sXy)
        EndIf
        If $wSize[0] > @DesktopWidth - $hDistance - $wSize[2] And $wSize[1] < $hDistance Then ; Top Right Hand Corner
            WinMove($aTitle, $hText, @DesktopWidth - $sXy - $wSize[2], $sXy)
        ElseIf $wSize[0] > @DesktopWidth - $hDistance - $wSize[2] Then ; Right Side Of Desktop
            WinMove($aTitle, $hText, @DesktopWidth - $sXy - $wSize[2], $wSize[1])
        EndIf
        If $wSize[1] > @DesktopHeight - $hDistance - $TaskBar - $wSize[3] And $wSize[0] < $hDistance Then ; Bottom Left Hand Corner
            WinMove($aTitle, $hText, $sXy, @DesktopHeight - $TaskBar - $wSize[3])
        ElseIf $wSize[1] > @DesktopHeight - $hDistance - $TaskBar - $wSize[3] Then ; Bottom Of Desktop
            WinMove($aTitle, $hText, $wSize[0], @DesktopHeight - $TaskBar - $wSize[3])
        EndIf
        If $wSize[1] > @DesktopHeight - $hDistance - $TaskBar - $wSize[3] And $wSize[0] > @DesktopWidth - $hDistance - $wSize[2] Then ; Bottom Right Hand Corner
            WinMove($aTitle, $hText, @DesktopWidth - $sXy - $wSize[2], @DesktopHeight - $TaskBar - $wSize[3])
        EndIf
    EndIf
EndFunc   ;==>_GuiSnap


$GUI = GUICreate('df',300,300,10,20)
GUISetState()
  _GuiSnap("df", '', 35, 4, 34)
While 1
 
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
    WEnd

dont work why?

Posted

Cough, Cough!

Umm ..... check the date.

We've had a few updates to AutoIt since then ... updates usually break some old feature/ability.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

It works as expected (despite the code being a little clumsy), I don't know what you expected. The changes that have taken place from 2008 to now wouldn't have really broken the script.

So in conclusion, be descriptive with what "doesn't work", what do you expect to happen that didn't?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)
  On 9/8/2013 at 1:20 PM, mesale0077 said:

dont work why?

You need to call the function at a regular time interval.

The below works for me as I put the function in the loop.

$GUI = GUICreate('df',300,300,10,20)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
    _GuiSnap("df", '', 35, 4, 34)
WEnd

If you move the window close to the edge of the monitor then it snaps to the edge. :)

Edit: Tested on Win7 with 3 monitors active in non surround mode if that means something to note.

Edited by MHz
Posted
  On 9/9/2013 at 9:14 AM, Mat said:

Might not work on windows 7+ as there is already the aero snap functionality and they might interfere with each other.

I tested on Windows 7.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

A lot of replies to someone who has been around long enough, to have provided proper detail in the first place, especially when engaging in Necromancy.  o:)

Now that I've had a look at the code and seen it is a very simple script, I'm kind of surprised at OP having to ask and providing so little info to give us some helpful clues.  :idea:

He'll probably come back and tell us he solved it himself days ago ... or even forgot he posted it.  :wacko:

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...