回复 14# snailyyy ;===============================================================================
;
; Function Name: _GUIEnhanceCtrlDrift
; Description:: Moves a control to ($iX, $iY) in a smooth manner
; Parameter(s): $hWnd - Window Handle
; $Ctrl - control id
; $iX - x pos to move to
; $iY - y pos to move to
; $iStep - number of pixels to move each step
; Requirement(s): None
; Return Value(s): 0, @error = 1 - Window doesn't exist
; 1 - Success
; Author(s): RazerM
; Note(s): Based on Bresenham's line drawing algorithm
; [url]http://www.falloutsoftware.com/tutorials/dd/dd4.htm[/url]
;
;===============================================================================
Func _GUIEnhanceCtrlDrift($hWnd, $Ctrl, $iX, $iY, $iStep = 1)
If Not WinExists($hWnd) Then Return SetError(1, 0, 0)
Local $aOldPos = ControlGetPos($hWnd, "", $Ctrl)
Local $iXOld = $aOldPos[0]
Local $iYOld = $aOldPos[1]
Local $fSteep = Abs($iY - $iYOld) > Abs($iX - $iXOld)
Local $aPoints[1][2]
Local $iOldX = $iX, $iOldY = $iY, $iYVal, $iYStep
Local $iDeltaX, $iDeltaY, $iError, $iDeltaError
If $fSteep Then
__Swap($iXOld, $iYOld)
__Swap($iX, $iY)
EndIf
If $iXOld > $iX Then
__Swap($iXOld, $iX)
__Swap($iYOld, $iY)
EndIf
$iDeltaX = $iX - $iXOld
$iDeltaY = Abs($iY - $iYOld)
$iError = 0
$iDeltaError = $iDeltaY / $iDeltaX
$iYVal = $iYOld
If $iYOld < $iY Then
$iYStep = 1
Else
$iYStep = -1
EndIf
For $iXVal = $iXOld To $iX
If $fSteep Then
ReDim $aPoints[UBound($aPoints) + 1][2]
$aPoints[UBound($aPoints) - 1][0] = $iYVal
$aPoints[UBound($aPoints) - 1][1] = $iXVal
Else
ReDim $aPoints[UBound($aPoints) + 1][2]
$aPoints[UBound($aPoints) - 1][0] = $iXVal
$aPoints[UBound($aPoints) - 1][1] = $iYVal
EndIf
$iError = $iError + $iDeltaError
If $iError >= 0.5 Then
$iYVal = $iYVal + $iYStep
$iError = $iError - 1
EndIf
Next
If $aPoints[1][0] = $iOldX And $aPoints[1][1] = $iOldY Then
For $iPoint = UBound($aPoints) - 1 To 1 Step $iStep * - 1
ControlMove($hWnd, "", $Ctrl, $aPoints[$iPoint][0], $aPoints[$iPoint][1])
Sleep(1)
Next
ControlMove($hWnd, "", $Ctrl, $aPoints[1][0], $aPoints[1][1])
Else
For $iPoint = 1 To UBound($aPoints) - 1 Step $iStep
ControlMove($hWnd, "", $Ctrl, $aPoints[$iPoint][0], $aPoints[$iPoint][1])
Sleep(1)
Next
ControlMove($hWnd, "", $Ctrl, $aPoints[UBound($aPoints) - 1][0], $aPoints[UBound($aPoints) - 1][1])
EndIf
Return 1
EndFunc ;==>_GUIEnhanceCtrlDrift
Func __Swap(ByRef $va, ByRef $vb)
Local $vTemp
$vTemp = $va
$va = $vb
$vb = $vTemp
EndFunc ;==>__Swap
|