autoit的響應模式分兩種,如果是使用事件回應模式則需要添加
1 |
Opt("GUIOnEventMode", 1);啟用事件回應模式 |
但切換到此模式下,默認的右上角的關閉點擊就無效,就是將$GUI_EVENT_CLOSE綁定到一個函數上,如
1 2 |
GUISetOnEvent($GUI_EVENT_CLOSE, "fuexit") ;EventMode设置窗口关闭事件 GUICtrlSetOnEvent($Form1, "fuexit");EventMode设置窗口关闭事件 |
1 2 3 4 |
Func Fuexit();點擊退出程式後,退出 GUIDelete(); Exit EndFunc ;==>Fuexit |
這樣就解決了。
幫助手冊當中的實例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) ; 切换到 OnEvent 模式 Local $hMainGUI = GUICreate("您好,世界", 200, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton") GUICtrlCreateLabel("世界您好!你怎么样?", 30, 10) Local $iOKButton = GUICtrlCreateButton("确定", 70, 50, 60) GUICtrlSetOnEvent($iOKButton, "OKButton") GUISetState(@SW_SHOW, $hMainGUI) While 1 Sleep(100) ; 休眠, 以降低 CPU 使用率 WEnd Func OKButton() ; 注意: 这里 @GUI_CtrlId 的值等于 $iOKButton, ; 而 @GUI_WinHandle 则等于 $hMainGUI. MsgBox($MB_OK, "GUI 事件", "你点击了 '确定' 按钮!") EndFunc ;==>OKButton Func CLOSEButton() ; 注意: 这里 @GUI_CtrlId 的值等于 $GUI_EVENT_CLOSE, ; 而 @GUI_WinHandle 的值等于 $hMainGUI MsgBox($MB_OK, "GUI 事件", "您选择了关闭窗口! 准备退出...") Exit EndFunc ;==>CLOSEButton |