GUIOnEventMode несовместим с GUIGetMsg.
Код:
#include <GUIConstantsEx.au3>
Opt('GUIOnEventMode', 1)
Opt('MustDeclareVars', 1)
Opt('TrayIconDebug', 1)
Opt('TrayIconHide', 0)
Global $REStart, $but1, $but2, $GUI
$GUI = GUICreate('Тест', 459, 240)
$but1 = GUICtrlCreateButton("Скрыть окно ", 26, 155, 172, 25)
$but2 = GUICtrlCreateButton("Выход", 26, 195, 172, 25)
$REStart = GUICtrlCreateButton('Перезапуск', 20, 60, 100, 25)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Events')
GUICtrlSetOnEvent($but1, '_Events')
GUICtrlSetOnEvent($but2, '_Events')
GUICtrlSetOnEvent($REStart, '_Events')
GUISetState()
While 1
Sleep(10)
WEnd
Func _Events()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE, $but2
Exit
Case $but1
GUISetState(@SW_HIDE, $GUI)
Case $REStart
_ReStart()
EndSwitch
EndFunc
Func _ReStart()
Local $sAutoIt_File = @TempDir & "\~Au3_ScriptRestart_TempFile.au3"
Local $sRunLine, $sScript_Content, $hFile
$sRunLine = @ScriptFullPath
If Not @Compiled Then $sRunLine = @AutoItExe & ' /AutoIt3ExecuteScript ""' & $sRunLine & '""'
If $CmdLine[0] > 0 Then $sRunLine &= ' ' & $CmdLineRaw
$sScript_Content &= '#NoTrayIcon' & @CRLF
$sScript_Content &= 'While ProcessExists(' & @AutoItPID & ')' & @CRLF
$sScript_Content &= ' Sleep(10)' & @CRLF
$sScript_Content &= 'WEnd' & @CRLF
$sScript_Content &= 'Run("' & $sRunLine & '")' & @CRLF
$sScript_Content &= 'FileDelete(@ScriptFullPath)' & @CRLF
$hFile = FileOpen($sAutoIt_File, 2)
FileWrite($hFile, $sScript_Content)
FileClose($hFile)
Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sAutoIt_File & '"', @ScriptDir, @SW_HIDE)
Sleep(1000)
Exit
EndFunc