Jump to content

_GuiSnap()


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 5 years later...

#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?

Link to comment
Share on other sites

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.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

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

Link to comment
Share on other sites

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:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

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

Link to comment
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
 Share

  • Recently Browsing   0 members

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