You need to remove the code that disabled it and add an event for the close
#include <misc.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIMenu.au3>
Opt("GUIOnEventMode", 1)
Global $gui
Func _Main()
$gui = GUICreate("hidecard", 100, 100, @DesktopWidth - (700 + 100), @DesktopHeight - (700 + 100), -1, $WS_EX_TOOLWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, 'button2')
$button1 = GUICtrlCreateButton("stop", 5, 65, 40, 20)
GUICtrlSetOnEvent(-1, "Button1")
$button2 = GUICtrlCreateButton("Off", 50, 65, 40, 20)
GUICtrlSetOnEvent(-1, "Button2")
; disable close button
;~ $hMenu = _GUICtrlMenu_GetSystemMenu($gui)
;~ _GUICtrlMenu_EnableMenuItem($hMenu, $SC_CLOSE, $MF_GRAYED, 0)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $gui, "int", 200, "long", 0x00040008); slide-in
WinSetOnTop($gui, "", 1) ; it's better to use the window hwnd, it's safer and faster than using the window title
TraySetState()
GUISetState()
EndFunc
_Main()
Func button2()
Exit
EndFunc
Func button1()
GUISetState(@SW_HIDE, $gui)
Sleep(5000) ; 5000 miliseconds = 5 secs
GUISetState(@SW_SHOW, $gui)
EndFunc
While 1
Sleep(10)
WEnd