本帖最后由 bdancerlc 于 2011-12-25 21:16 编辑
原帖:http://www.autoitx.com/forum.php ... hlight=%B8%FA%CB%E6
错误提示:
错误: $WM_MOVING 上一次定义为一个 'Const' 变量..
Global Const $WM_MOVING = 0x216
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
Global Const $WM_MOVING = 0x216
Global $from2_s = False
$From1 = GUICreate('移动我', 300, 300, 300, 300)
$pos1 = WinGetPos($From1)
GUIRegisterMsg($WM_MOVING, 'WM_MOVING')
GUIRegisterMsg(0x3, "WM_MOVE")
GUISetState()
$From2 = GUICreate('', 300, 300, 600, 300, -1, -1, $From1)
GUISetState()
$from1_pos = WinGetPos($From1)
Do
Until GUIGetMsg() = -3
Func WM_MOVING($hWnd, $iMsg, $iwParam, $ilParam)
GUIRegisterMsg(0x3, "")
If $hWnd = $From1 And $from2_s = False Then
$tBuffer = DllStructCreate($tagRECT, $ilParam) ;$tagRECT结构,包含左、顶、右、底坐标
$iLeft = DllStructGetData($tBuffer, "Left")
$iTop = DllStructGetData($tBuffer, "Top")
WinMove($From2, "", $iLeft + $from1_pos[2], $iTop)
WinMove($From1, "", $iLeft, $iTop)
Return
Else
$from2_s = True
EndIf
If $hWnd = $From2 Then
$tBuffer = DllStructCreate($tagRECT, $ilParam) ;$tagRECT结构,包含左、顶、右、底坐标
$iLeft = DllStructGetData($tBuffer, "Left")
$iTop = DllStructGetData($tBuffer, "Top")
$from1_pos = WinGetPos($From1)
$x = $from1_pos[0] + $from1_pos[2] - $iLeft
$y = $from1_pos[1] - $iTop
If Abs($x) < 30 And Abs($y) < 30 Then WinMove($From2, "", $from1_pos[0] + $from1_pos[2], $from1_pos[1])
EndIf
GUIRegisterMsg(0x3, "WM_MOVE")
EndFunc ;==>WM_MOVING
Func WM_MOVE()
$from1_pos = WinGetPos($From1)
$from2_pos = WinGetPos($From2)
$x = $from1_pos[0] + $from1_pos[2] - $from2_pos[0]
$y = $from1_pos[1] - $from2_pos[1]
If Abs($x) < 30 And Abs($y) < 30 Then
WinMove($From2, "", $from1_pos[0] + $from1_pos[2], $from1_pos[1])
$from2_s = False
EndIf
EndFunc ;==>WM_MOVE
|