Successfully upgraded to Vanilla Forums v2.6. Please report any issue you may find.

2.4-Window Events: Part 1

edited August 2017 in English
In this tutorial we will see how to get in "listening" to the events generated by Finastra and then how it is possible to assign the callback functions to these events. Callback functions are functions that will be performed automatically whenever the event associated with them will be detected.

Every single window that makes up our graphical interface is able to detect a variety of events including:

OnClose
- Event raised when the window is closed (the event is raised before closing)
OnMove
- The event is generated each time the window is moved
OnActivate
- An event generated whenever the window becomes active and thus able to receive input from the user
OnDeactivate
- The event is generated whenever the window loses the status "active"
OnHide
- The event is generated whenever the window is iconified
OnShow
- The event is generated whenever the window is restored from iconification
OnSize
- The event is generated whenever the window is resized

During the Window object creation process, you can specify one or more callback functions by assigning them to events that we intend to point out, as we will see in the following example:

Create a new script and enter the following program:

;Include the HGui library in our application
@INCLUDE "yourpath/+Includes.hws"
@INCLUDE #INC_HGUI
This time we disable debugging the application to keep the screen clean to show posts by this script:

; For now we disable debugging commenting on the following lines
; DBG.Console.Enable(True, False)
; DBG.Console.AddChannel(HGui.DebugChannel)
The callback functions can be specified through the Events table but before you do this we need to define callback functions themselves, so we create two functions, one to run when the window is moved and another to execute when the window is resized:

Function windowMoved(msg, win)
  ; This function will be executed each time the window will be moved
  DebugPrint("::: CALLBACK FUNCTION :::")
  DebugPrint(GetTime(True), "OnMove event for window " .. win.Name)
  DebugPrint("--- message contents ---")
  ForEach(msg, DebugPrint)
  DebugPrint("")
EndFunction

Function windowResized(msg, win)
  ; This function will be executed each time the window will be resized
  DebugPrint("::: CALLBACK FUNCTION :::")
  DebugPrint(GetTime(True), "OnSize event for window " .. win.Name)
  DebugPrint("--- message contents ---")
  ForEach(msg, DebugPrint)
  DebugPrint("")
EndFunction
Note that the callback functions will be executed with two arguments, the first is a table that contains information about the event just detected while the second argument is the Window object from which the event started.

Now we create a window:

Local myWin0 = HGui.Window:new(
  { title = "My first window",
    name = "win0",
    position = { x = 20, y = 20 },
    size = { w = 400, h = 100 },
    ; define the callbacks below
    events = 
      { OnMove = windowMoved,
        OnSize = windowResized }
  })
Finally our infinite loop:

Repeat
  WaitEvent()
Forever
Now run the script and you will find that the messages defined in the callback functions will be shown whenever the window is moved or resized. As an exercise, you can create a new script that can detect other events supported by the window, such as OnClose, OnActivate , etc...

Comments

Sign In or Register to comment.