Sign in to follow this  
Followers 0
PlayHD

Snaping

4 posts in this topic

Hey.

I want to make a script that when you click a control to be able to move it with mouse.

All good until i think to add snaping.

I try to fix it but I found no solution.

I ask you for help.

Here is my script : Script.au3

Thanks in advance.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Have a look at the

I will post back an example after a while

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I have added Left/Right Snapping example

Hope you could do it for Top/Bottom

#include <GUIConstantsEx.au3>
#include <WinApi.au3>
#include <Misc.au3>


;Priority of Check
;Left/Right - Have to check the X coordinate


Global $Form1 = GUICreate("Form1", 615, 437, 192, 124)
Global $Button1 = GUICtrlCreateButton("Button1", 150, 144, 350, 120)
Global $Button2 = GUICtrlCreateButton("Button2", 10, 100, 75, 25)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_PRIMARYDOWN
$GuICurMsg = GUIGetCursorInfo($Form1)
If IsArray($GuICurMsg) Then _ControlMove($GuICurMsg)
EndSwitch
WEnd

Func _ControlMove($cMmsg)

Local $cID = $cMmsg[4]
If $cID < 3 Then Return ;Required for Fast Clicks

Local $SelPos = ControlGetPos($Form1, "", $cID)

Local $Form1Pos = WinGetPos($Form1)

Local $Form1Width = _WinAPI_GetWindowWidth($Form1)

Local $Form1Height = _WinAPI_GetWindowHeight($Form1)

Local $SubstractX, $SubstractY
$SubstractX = $cMmsg[0] - $SelPos[0]
$SubstractY = $cMmsg[1] - $SelPos[1]

_MouseTrapGUI()

While _IsPressed("01")
$cMmsg = GUIGetCursorInfo($Form1)
If _SnappedEdge($cID) And _MouseinCTL($cMmsg,$cID) Then ContinueLoop
GUICtrlSetPos($cID, $cMmsg[0] - $SubstractX, $cMmsg[1] - $SubstractY) ;Mouse Trap will always cause to return the array in cMmsg
WEnd
Return _MouseTrap()
EndFunc ;==>_ControlMove

Func _MouseTrapGUI()
Local $tPoint = DllStructCreate("int X;int Y")
DllStructSetData($tPoint, "X", 0)
DllStructSetData($tPoint, "Y", 0)
_WinAPI_ClientToScreen($Form1, $tPoint)
Local $X = DllStructGetData($tPoint, "X")
Local $Y = DllStructGetData($tPoint, "Y")
Return _MouseTrap($X, $Y, $X + _WinAPI_GetClientWidth($Form1), $Y + _WinAPI_GetClientHeight($Form1))
EndFunc ;==>_MouseTrapGUI


Func _SnappedEdge($iCtl, $iMinDistance = 15, $iStep = 1)
Local $aPosc = ControlGetPos($Form1, '', $iCtl)

Local $nCtl
If $iCtl = $Button1 Then
$nCtl = $Button2
Else
$nCtl = $Button1
EndIf
Local $aPosd = ControlGetPos($Form1, '', $nCtl)

;Lets check the X coordinates for Left/Right snapping
For $i = $iMinDistance * - 1 To $iMinDistance Step $iStep
If $aPosd[0] = $aPosc[0] + $i Then Return GUICtrlSetPos( $iCtl, $aPosd[0] ) ;Left-Snap
If $aPosd[0] = $aPosc[0] + $aPosc[2] + $i Then Return GUICtrlSetPos( $iCtl, $aPosd[0] - $aPosc[2] ) ;Right-Left Snap
If $aPosd[0] + $aPosd[2] = $aPosc[0] + $i Then Return GUICtrlSetPos( $iCtl, $aPosd[0] + $aPosd[2] ) ;Left-Right Snap
If $aPosd[0] + $aPosd[2] = $aPosc[0] + $aPosc[2] + $i Then Return GUICtrlSetPos( $iCtl, $aPosd[0] + $aPosd[2] - $aPosc[2] ) ;Right-Snap
Next

EndFunc ;==>_SnappedEdge

Func _MouseinCTL($aCur,$iCtl)
If $aCur[4] = $iCtl Then Return True
Return False
EndFunc
Thumbs up if it helped

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Check the post again, it will even Snap the Left Edge with the Right Edge and vice-versa

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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  
Followers 0