#include <GUIConstantsEx.au3>
$Guititle="12333"
Global $__title,$__text,$__x, $__y
Global $Timer
Global $TimerDLL
$Form1 = GUICreate($Guititle, 220, 100, 80, 100)
$Button1 = GUICtrlCreateButton('test', 150, 35, 60, 20)
GUISetState()
While 1
Switch GUIGetMsg()
Case -3
Exit
Case $Button1
MsgboxM(0, 'test', '我将跟随主窗口~')
MsgboxM(0, 'test', '我将定位到500,200的位置', 500, 200)
EndSwitch
WEnd
Func MsgboxM($flag, $title, $text, $x = '', $y = '')
$__title = $title
$__text = $text
$__x = $x
$__y = $y
$Timer = DllCallbackRegister('Timer', 'int', 'hwnd;uint;uint;dword')
$TimerDLL = DllCall('user32.dll', 'uint', 'SetTimer', 'hwnd', 0, 'uint', _
0, 'int', 1, 'ptr', DllCallbackGetPtr($Timer))
Sleep(3)
MsgBox($flag, $title, $text)
EndFunc ;==>MsgboxM
Func Timer($hwnd, $uiMsg, $idEvent, $dwTime)
If $idEvent = $TimerDLL[0] Then
$Wpos = WinGetPos($Guititle)
Local $x = $Wpos[0] + 60, $y = $Wpos[1] + 10
If StringIsDigit($__x) And StringIsDigit($__y) Then Local $x = $__x, $y = $__y
If WinMove($__title, $__text, $x, $y) <> 0 Then
DllClose($TimerDLL)
DllCallbackFree($Timer)
EndIf
EndIf
EndFunc ;==>Timer