Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;~ Par défaut dans AutoIt "ESC" correspond au clic sur la croix de fermeture de la gui
;~ Le comportement est différent si la hotkey est posée pour quitter le script :
HotKeySet("{ESC}", "_exit")
Opt("GuiOnEventMode", 1)
GUICreate("My GUI")
GUISetOnEvent($GUI_EVENT_CLOSE, "_close")
$btn = GUICtrlCreateButton("stop", 10, 50, 50, 20)
GUICtrlSetOnEvent(-1, "_btn")
$label = GUICtrlCreateLabel("0", 100, 50, 20, 20)
GUISetState()
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")
Local $aAccelKeys[1][2] = [["{SPACE}", $btn]]
GUISetAccelerators($aAccelKeys)
Global $stop = 0, $close = 0
While 1
If $stop <> 0 Then Exitloop
If $close <> 0 Then Exit
Sleep(300)
GuiCtrlSetData($label, GuiCtrlRead($label)+1)
Wend
Msgbox(64,"", "stopped")
Opt("GuiOnEventMode", 0)
While 1
Switch GuiGetMsg()
Case $GUI_EVENT_CLOSE
$close = 4
Msgbox(64, $close, "close GuiGetMsg")
Case $btn
Msgbox(64, "", "bouton GuiGetMsg")
EndSwitch
If $close <> 0 Then Exit
Sleep(10)
Wend
;=========================================
;~ fonction appelée par eventmode (bouton)
Func _btn()
$stop = 1
Msgbox(64, $stop, "bouton on event")
EndFunc
;~ fonction appelée par eventmode (croix)
Func _close()
$close = 1
Msgbox(64, $close, "close on event")
EndFunc
;~ interception du message Windows (bouton)
Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $lParam
If BitAND($wParam, 0xFFFF) = $btn Then
$stop = 2
Msgbox(64, $stop, "bouton wm_command")
EndIf
Return 'GUI_RUNDEFMSG'
EndFunc
;~ interception du message Windows (croix)
Func _WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $lParam
If BitAND($wParam, 0xFFF0) = 0xF060 Then ; 0xF060 = $SC_CLOSE
$close = 2
Msgbox(64, $close, "close wm_syscommand")
EndIf
EndFunc
;~ fonction appelée par HotKeySet ESC
Func _exit()
$close = 3
Msgbox(64, $close, "close hotkey")
EndFunc