GUIGetMsg
获取窗口事件消息.
GUIGetMsg ( [advanced = 0] )
参数
advanced
|
[可选] 返回扩展信息数组.
$GUI_EVENT_SINGLE (0) = (默认)返回单一事件.
$GUI_EVENT_ARRAY (1) = 返回含有事件及扩展信息的数组.
常量定义在 GUIConstantsEx.au3
|
返回值
返回事件或数组, 取决于"advanced"的参数设置.
返回"事件"为发送消息的控件 ID, 或某个特殊事件(例如窗口关闭,最小化). 若没有消息, 则返回事件值为 0.
事件 ID:
|
控件发送的消息
|
$GUI_EVENT_NONE (0):
|
无事件
|
$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 或文件.
|
常量定义在 GUIConstantsEx.au3.
当使用"advanced"时, 函数返回下列扩展信息的数组:
$aArray[0] = 0 或 事件 ID 或 控件 ID
$aArray[1] = 产生事件的窗口句柄
$aArray[2] = 产生事件的控件句柄(若适用)
$aArray[3] = 鼠标光标当前 X 坐标(相对于 GUI 窗口)
$aArray[4] = 鼠标光标当前 Y 坐标(相对于 GUI 窗口)
如果 GUIOnEventMode 选项设为 1, 则 GUIGetMsg 的返回值将总是 0, 同时 @error 被设为 1.
如果 GUIEventOptions 选项设为 1, 则最小化, 还原和最大化按钮不会对窗口有有任何动作, 只是一个简单的通知.
备注
函数执行时将自动按需闲置 CPU. 因此可以放心地在紧凑的循环中使用本函数, 不必担心 CPU 的负荷问题.
有关鼠标悬停的位置和控件信息, 使用 GUIGetCursorInfo() 函数检索.
当鼠标停留在某个控件而不激发事件, 同样可以调用 GUIGetCursorInfo() 函数检索控件 ID.
相关
GUICreate, GUICtrlCreate..., GUICtrlRead, GUICtrlSendMsg, GUICtrlSetOnEvent, GUIEventOptions (Option), GUIGetCursorInfo, GUIOnEventMode (Option)
函数示例
示例 1
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Example()
; -------------------------------------------------------------------------------------
; Example - Press the button to see the value of the radio boxes
; The script also detects state changes (closed/minimized/timeouts, etc).
Func Example()
Opt("GUICoordMode", 1)
GUICreate("Radio Box Demo", 400, 280)
; Create the controls
Local $idButton_1 = GUICtrlCreateButton("B&utton 1", 30, 20, 120, 40)
GUICtrlCreateGroup("Group 1", 30, 90, 165, 160)
GUIStartGroup()
Local $idRadio_1 = GUICtrlCreateRadio("Radio &0", 50, 120, 70, 20)
GUICtrlCreateRadio("Radio &1", 50, 150, 60, 20)
Local $idRadio_3 = GUICtrlCreateRadio("Radio &2", 50, 180, 60, 20)
; Init our vars that we will use to keep track of GUI events
Local $iRadioVal1 = 0 ; We will assume 0 = first radio button selected, 2 = last button
; Show the GUI
GUISetState(@SW_SHOW)
Local $idMsg = 0
; In this message loop we use variables to keep track of changes to the radios, another
; way would be to use GUICtrlRead() at the end to read in the state of each control
While 1
$idMsg = GUIGetMsg()
Select
Case $idMsg = $GUI_EVENT_CLOSE
MsgBox($MB_SYSTEMMODAL, "", "Dialog was closed")
ExitLoop
Case $idMsg = $GUI_EVENT_MINIMIZE
MsgBox($MB_SYSTEMMODAL, "", "Dialog minimized", 2)
Case $idMsg = $GUI_EVENT_MAXIMIZE
MsgBox($MB_SYSTEMMODAL, "", "Dialog restored", 2)
Case $idMsg = $idButton_1
MsgBox($MB_SYSTEMMODAL, "", "Default button clicked:" & @CRLF & "Radio " & $iRadioVal1)
Case $idMsg >= $idRadio_1 And $idMsg <= $idRadio_3
$iRadioVal1 = $idMsg - $idRadio_1
EndSelect
WEnd
GUIDelete()
EndFunc ;==>Example
示例 2
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Create a GUI.
Local $hGUI1 = GUICreate("Example GUI1")
; Create a button.
Local $idButton1 = GUICtrlCreateButton("Button1", 10, 10, 80, 22)
; Display the GUI
GUISetState(@SW_SHOW, $hGUI1)
; Create a GUI.
Local $hGUI2 = GUICreate("Example GUI2", 300, 300)
; Create a button.
Local $idButton2 = GUICtrlCreateButton("Button2", 10, 10, 80, 22)
; Display the GUI
GUISetState(@SW_SHOW, $hGUI2)
; Initialize a Local variable.
Local $aMsg = 0
While 1
; Assign to $aMsg the advanced GUI messages.
$aMsg = GUIGetMsg($GUI_EVENT_ARRAY)
; Switch from GUIs
Switch $aMsg[1]
Case $hGUI1
; The event comes from the GUI1
; Switch from event ID
Switch $aMsg[0]
Case $GUI_EVENT_CLOSE
ExitLoop
Case $idButton1
MsgBox($MB_SYSTEMMODAL, "", "Button1 clicked.")
EndSwitch
Case $hGUI2
; The event comes from the GUI2
; Switch from event ID
Switch $aMsg[0]
Case $GUI_EVENT_CLOSE
GUIDelete($hGUI2)
Case $idButton2
MsgBox($MB_SYSTEMMODAL, "", "Button2 clicked.")
EndSwitch
EndSwitch
WEnd
; Delete the previous GUIs and all controls.
GUIDelete($hGUI1)
EndFunc ;==>Example
----------------------------------------
|