#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 439, 297, 281, 213)
$Button1 = GUICtrlCreateButton("点我试试", 176, 128, 75, 25, 0)
GUISetState(@SW_SHOW, $Form1)
$Timer = DllCallbackRegister("_WinCenter", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 0, "ptr", DllCallbackGetPtr($Timer))
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$xy = WinGetPos($Form1, "")
$Form2 = GUICreate("这是创建的新GUI可以实现", 225, 109, $xy[0] + ($xy[2] - 225) / 2, $xy[1] + ($xy[3] - 109) / 2)
$Button2 = GUICtrlCreateButton("关闭", 64, 40, 75, 25, 0)
GUISetState(@SW_SHOW, $Form2)
MsgBox(0, "test", "这是MsgBox弹出来的提示框,如何在主窗口居中呢?", $Form1)
While 1
$nMsg2 = GUIGetMsg()
Switch $nMsg2
Case $Button2
GUIDelete($Form2)
ExitLoop
EndSwitch
WEnd
EndSwitch
WEnd
Func _WinCenter($hWnd, $uiMsg, $idEvent, $dwTime)
If $idEvent = $TimerDLL[0] Then
$pos = WinGetPos($Form1)
If Not @error Then _
WinMove('[CLASS:#32770]', "这是MsgBox弹出来的提示框,如何在主窗口居中呢?", $pos[0] + 52, $pos[1] + 80)
WinSetOnTop('[CLASS:#32770]', "这是MsgBox弹出来的提示框,如何在主窗口居中呢?", 1)
EndIf
EndFunc ;==>_WinCenter