本帖最后由 smartzbs 于 2011-1-25 16:18 编辑
鼠标移到Button按钮上,按下鼠标左键不放拖动该按钮.#Include <Misc.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
Example()
Func Example()
Local $Button_1, $msg, $aPos, $aTemp
$Form = GUICreate("My GUI Button")
$Button_1 = GUICtrlCreateButton("Button", 10, 30, 100, 30)
$aButton_1 = ControlGetPos($Form, "", $Button_1)
GUISetState()
; Run the GUI until the dialog is closed
While 1
If _Hover($Form, $aButton_1[0], $aButton_1[1], $aButton_1[2], $aButton_1[3]) Then
While _IsPressed(1)
If Not IsArray($aPos) Then $aPos = MouseGetPos()
$aTemp = MouseGetPos()
If $aTemp[0] <> $aPos[0] Or $aTemp[1] <> $aPos[1] Then
ControlMove($Form, "", $Button_1, $aButton_1[0]+($aTemp[0]-$aPos[0]), $aButton_1[1]+($aTemp[1]-$aPos[1]) )
EndIf
WEnd
$aButton_1 = ControlGetPos($Form, "", $Button_1)
$aPos = ""
EndIf
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button_1
EndSelect
WEnd
EndFunc ;==>Example
Func _Hover($cH_hWin = "", $Pos_X = 0, $Pos_Y = 0, $Pos_W = 0, $Pos_H = 0)
$cH_Data = GUIGetCursorInfo($cH_hWin)
If Not IsArray($cH_Data) Then Return SetError(10086)
If $cH_Data[0] > $Pos_X And $cH_Data[0] < $Pos_X + $Pos_W And $cH_Data[1] > $Pos_Y And $cH_Data[1] < $Pos_Y + $Pos_H Then
Return 1
Else
Return 0
EndIf
EndFunc
|