2月152017
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```
<br />
扫描二维码,在手机上阅读
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!