是不是改成这样比较好?
#include <Timers.au3>
$Gui = GUICreate("Gui_1")
$Button_1 = GUICtrlCreateButton("Button1", 10, 30, 100)
$Gui_2 = GUICreate("Gui_2", 150, 150, -1, -1, -1, -1, $Gui)
$Button_2 = GUICtrlCreateButton("Button2", 10, 30, 50)
GUISetState(@SW_SHOW, $Gui)
While 1
$msg = GUIGetMsg()
Select
Case $msg = -3
_Timer_KillAllTimers($Gui_2)
If WinGetState($Gui_2) = 5 Then
ExitLoop
Else
GUISetState(@SW_HIDE, $Gui_2)
EndIf
Case $msg = $Button_1
$TimerDLL = _Timer_SetTimer($Gui_2, 10, "Opos")
GUISetState(@SW_SHOW, $Gui_2)
EndSelect
WEnd
Func Opos($hWnd, $uiMsg, $idEvent, $dwTime)
$CursorInfo = GUIGetCursorInfo()
If $idEvent = $TimerDLL Then
If WinExists($Gui_2) Then
Local $MainWindow = WinGetPos($Gui)
Local $SubWindow = WinGetPos($Gui_2)
WinMove($Gui_2, "", $MainWindow + ($MainWindow / 2) - ($SubWindow / 2), _
$MainWindow + ($MainWindow / 2) - ($SubWindow / 2))
EndIf
EndIf
EndFunc ;==>Opos 给你个官方的例子
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <misc.au3>
Opt("GuiOnEventMode",1)
Opt("MustDeclareVars",1)
Global $HWNDMAIN, $GUI_W = 800, $GUI_H = 600
Global $HWNDCHILD, $Child_W = 600, $Child_H = 400
Global $activePackage = 0, $activeChildren = , $GUI_CTRLID = 0
$HWNDMAIN = GUICreate("Main", $GUI_W, $GUI_H, Default, Default)
GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit")
GUISetState()
$HWNDCHILD = GUICreate("",$Child_W,$Child_H,100, 100, BitOR($WS_POPUP,$WS_BORDER),$WS_EX_MDICHILD,$HWNDMAIN)
GUISetBkColor(0xFFFFBB)
GUISetState()
$activePackage = $HWNDCHILD ;Simulates something from full script
GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING")
_CreateCell($HWNDCHILD, 136, 142 )
_CreateCell($HWNDCHILD, 136, 142 )
While 1
Sleep(250)
WEnd
Func WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
ConsoleWrite("WM_WINDOWPOSCHANGING" & @CRLF)
Local $i, $activeCell = 0
For $i = 1 to $activeChildren
If $hWnd = $activeChildren[$i] then
$activeCell = $HWND
ConsoleWrite($activeCell & @CRLF)
ExitLoop
EndIf
Next
If WinActive($HWNDMAIN) then Return
If $hWnd <> $activeCell then Return
If $activePackage = 0 then Return
Local $aMain_Pos = WinGetPos($activePackage) ;Get the position of the ParentCell
If NOT IsArray($aMain_Pos) then Return
Local $aCell_Pos = WinGetPos($HWND) ;<< patch
If NOT IsArray($aCell_Pos) then Return
;Get the position of the window which is currently dragging and specify the drag limits
Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
Local $iLeft = DllStructGetData($stWinPos, 3)
Local $iTop = DllStructGetData($stWinPos, 4)
Local $iWidth = $aCell_Pos ;<< patch DllStructGetData($stWinPos, 5)
Local $iHeight = $aCell_Pos ;<< patch DllStructGetData($stWinPos, 6)
If DllStructGetData($stWinPos, 5) <> $iWidth then DllStructSetData($stWinPos, 5, $iWidth)
If DllStructGetData($stWinPos, 6) <> $iHeight then DllStructSetData($stWinPos, 6, $iHeight)
Local $iX_Min = $aMain_Pos
Local $iY_Min = $aMain_Pos
Local $iX_Max = ($aMain_Pos + $aMain_Pos) - $iWidth
Local $iY_Max = ($aMain_Pos + $aMain_Pos) - $iHeight
ConsoleWrite("X = " & $iLeft & @CRLF & _
"Y = " & $iTop & @CRLF & _
"W = " & $iWidth & @CRLF & _
"H = " & $iHeight & @crlf)
If $iLeft < $iX_Min Then DllStructSetData($stWinPos, 3, $iX_Min)
If $iLeft > $iX_Max Then DllStructSetData($stWinPos, 3, $iX_Max)
If $iTop < $iY_Min Then DllStructSetData($stWinPos, 4, $iY_Min)
If $iTop > $iY_Max Then DllStructSetData($stWinPos, 4, $iY_Max)
Return $GUI_RUNDEFMSG
EndFunc
Func _CreateCell($vHWND, $w,$h )
Local $HWNDCHILD = GUICreate("",$w, $h, 1, 1, BitOR($WS_POPUP,$WS_BORDER),$WS_EX_MDICHILD,$vHWND)
GUICtrlCreatePic(@ProgramFilesDir & "\AutoIt3\Examples\GUI\Merlin.gif",0,0,$w,$h, $WS_CLIPSIBLINGS ,$GUI_WS_EX_PARENTDRAG)
GUICtrlCreateLabel("",0,0,$w,$h,Default,$GUI_WS_EX_PARENTDRAG)
GUICtrlSetOnEvent(-1,"_MouseClick")
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUISetState()
ReDim $activeChildren[$activeChildren +2]
$activeChildren[$activeChildren +1] = $HWNDCHILD
$activeChildren +=1
Return $HWNDCHILD
EndFunc
Func _MouseClick()
$GUI_CTRLID = @GUI_CtrlId
EndFunc
Func _Exit()
Exit
EndFunc 谢谢,非常感谢
页:
1
[2]