当一个系统按钮被点击时调用一个用户自定义函数(UDF).
GUISetOnEvent ( 特殊ID, "函数名" [, 窗口句柄] )
特殊ID | 见下面的 特殊ID表. |
函数名 | 要调用的用户函数. |
窗口句柄 | [可选参数] 窗口句柄,可由 GUICreate 的返回值获得(若使用默认(default)则使用上一次用过的句柄.) |
成功: | 返回 1. |
失败: | 返回 0. |
特殊 Id | 说明 |
---|---|
$GUI_EVENT_CLOSE | 对话框(窗口)正被关闭(相关按钮被点击或系统菜单项被选中). |
$GUI_EVENT_MINIMIZE | 对话框(窗口)被最小化(窗口标题栏上的最小化按钮被点击). |
$GUI_EVENT_RESTORE | 对话框(窗口)被还原(任务栏图标被点击). |
$GUI_EVENT_MAXIMIZE | 对话框(窗口)被最大化(窗口标题栏上的最大化按钮被点击). |
$GUI_EVENT_MOUSEMOVE | 鼠标指针移动. |
$GUI_EVENT_PRIMARYDOWN | 鼠标的主要按钮被按下. |
$GUI_EVENT_PRIMARYUP | 鼠标的主要按钮被松开. |
$GUI_EVENT_SECONDARYDOWN | 鼠标的次要按钮被按下. |
$GUI_EVENT_SECONDARYUP | 鼠标的次要按钮被松开. |
$GUI_EVENT_RESIZED | 对话框大小改变. |
$GUI_EVENT_DROPPED | 结束拖放操作 @GUI_DRAGID, @GUI_DRAGFILE 和 @GUI_DROPID 将返回一个相关的ID,文件通信到相关控件. |
#include <GUIConstantsEx.au3>
Example()
Func Example()
Opt("GUICoordMode", 2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)
GUICreate("Parent1")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
GUICtrlCreateButton("OK", 10, 30, 50)
GUICtrlSetOnEvent(-1, "OKPressed")
GUICtrlCreateButton("Cancel", 0, -1)
GUICtrlSetOnEvent(-1, "CancelPressed")
GUISetState(@SW_SHOW)
; Just idle around
While 1
Sleep(10)
WEnd
EndFunc ;==>Example
Func OKPressed()
MsgBox(4096, "OK Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc ;==>OKPressed
Func CancelPressed()
MsgBox(4096, "Cancel Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc ;==>CancelPressed
Func SpecialEvents()
Select
Case @GUI_CtrlId = $GUI_EVENT_CLOSE
MsgBox(4096, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
Exit
Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
MsgBox(4096, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
Case @GUI_CtrlId = $GUI_EVENT_RESTORE
MsgBox(4096, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
EndSelect
EndFunc ;==>SpecialEvents