; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>Example Function Reference GUICtrlSetOnEvent định nghĩa
Trang 1; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc ;==>Example
Function Reference
GUICtrlSetOnEvent
định nghĩa 1 hàm sẽ đc gọi tới khi sự kiện sảy ra trên control
GUICtrlSetOnEvent ( controlID, "function" )
Parameters
controlID control id
function tên hàm
Return Value
Success: Returns 1
Failure: Returns 0,
Remarks
chế độ onevent chỉ có hiẹu lực khi ta chuyển sang nó = cách opt(
GUIOnEventMode, 1) khi đó chế độ mặc định GUIGetMsg sẽ ko dùng đc nữa các macro đặc biệt
Trang 2@GUI_CTRLID: controlID đã sảy ra sự kiện
@GUI_WINHANDLE và @GUI_CTRLHANDLE GUI handle, control handle sảy
ra sự kiện
nếu tên hàm function = "" thì có nghĩa là bỏ hàm, khi sự kiện sảy ra trên control đó thì chẳng làm gì cả
Related
GUICreate, GUICtrlCreate , GUIGetMsg, GUIOnEventMode (Option),
GUISetOnEvent
Example
#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Example()
Func Example()
Local $parent1, $ok1, $cancel1
Opt("GUICoordMode", 2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)
$parent1 = GUICreate("Parent1")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
$ok1 = GUICtrlCreateButton("OK", 10, 30, 50)
GUICtrlSetOnEvent(-1, "OKPressed")
$cancel1 = GUICtrlCreateButton("Cancel", 0, -1)
GUICtrlSetOnEvent(-1, "CancelPressed")
GUISetState(@SW_SHOW)
Trang 3; Just idle around
While 1
Sleep(10)
WEnd
EndFunc ;==>Example
Func OKPressed()
MsgBox(0, "OK Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" &
@GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc ;==>OKPressed
Func CancelPressed()
MsgBox(0, "Cancel Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" &
@GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc ;==>CancelPressed
Func SpecialEvents()
Select
Case @GUI_CtrlId = $GUI_EVENT_CLOSE
MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" &
@GUI_WinHandle)
Exit
Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
MsgBox(0, "Window Minimized", "ID=" & @GUI_CtrlId & "
WinHandle=" & @GUI_WinHandle)
Case @GUI_CtrlId = $GUI_EVENT_RESTORE
MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle="
& @GUI_WinHandle)
EndSelect
EndFunc ;==>SpecialEvents
Trang 4Function Reference
GUICtrlSetPos
thay đổi vị trí của control trên GUI
GUICtrlSetPos ( controlID, left, top [, width [, height]] )
Parameters
controlID controlID
height H
Return Value
Success: Returns 1
Failure: Returns 0
Remarks
None
Related
GUICtrlCreate
Example
#include <GUIConstantsEx.au3>
Trang 5Opt('MustDeclareVars', 1)
Example()
Func Example()
Local $right, $label, $button, $msg
GUICreate("My GUI position") ; will create a dialog box that when displayed is centered
$right = 0
$label = GUICtrlCreateLabel("my moving label", 10, 20)
$button = GUICtrlCreateButton("Click to close", 50, 50)
GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button
GUISetState()
While 1
$msg = GUIGetMsg()
If $msg = $button Or $msg = $GUI_EVENT_CLOSE Then Exit
If $right = 0 Then
$right = 1
GUICtrlSetPos($label, 20, 20)
Else
$right = 0
GUICtrlSetPos($label, 10, 20)
EndIf
Sleep(100)
WEnd
EndFunc ;==>Example