Function Reference

GUISetOnEvent

Defines a user function to be called when a system button is clicked.

GUISetOnEvent ( specialID, "function" [, winhandle] )

 

Parameters

specialID See the Special ID table below.
function The name of the user function to call.
winhandle [optional] Windows handle as returned by GUICreate (default is the previously used window).

 

Return Value

Success: Returns 1.
Failure: Returns 0.

 

Remarks

OnEvent functions are only called when the option GUIOnEventMode is set to 1 - when in this mode GUIGetMsg is NOT used at all.

If the option GUIEventOptions is set to 1 the minimize, restore and maximize button will not do any action on the window just a simple notification.

If the function is an empty string "" the previous user-defined is disabled.

    Special ID table
Special Id Comments
$GUI_EVENT_CLOSE dialog box being closed (either by defined button or system menu).
$GUI_EVENT_MINIMIZE dialog box minimized with Windows title bar button.
$GUI_EVENT_RESTORE dialog box restored by click on task bar icon.
$GUI_EVENT_MAXIMIZE dialog box maximized with Windows title bar button.
$GUI_EVENT_MOUSEMOVE the mouse cursor has moved.
$GUI_EVENT_PRIMARYDOWN the primary mouse button was pressed.
$GUI_EVENT_PRIMARYUP the primary mouse button was released.
$GUI_EVENT_SECONDARYDOWN the secondary mouse button was pressed.
$GUI_EVENT_SECONDARYUP the secondary mouse button was released.
$GUI_EVENT_RESIZED dialog box has been resized.
$GUI_EVENT_DROPPED End of a Drag&Drop action @GUI_DRAGID, @GUI_DRAGFILE and @GUI_DROPID will be used to retrieve the ID's/file corresponding to the involve control.

 

Related

GUIOnEventMode (Option), GUIEventOptions (Option), GUICtrlSetOnEvent

 

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)


    ; 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