When a user interface element (window, control, menu) is created, a special predicate must be defined to handle incoming messages.
The first argument of such a predicate is a message name. Presently
this can be one of the following:
|init||sent upon window creation. It is sent before the first paint message. The init message is useful for creation of menus and buttons.
|paint||the window has to be redrawn. This message is sent every time some part of the window's client area needs to be redrawn. See also paint_rect.
|close||someone tries to close the window. If the window's function does not process this message or fails while processing
the window will close, otherwise it will not close (sample Sun.spj).
|size(X,Y)||the window changed its size and the new size of its client
area is X, Y.
|char(Char, Repetition)||this message is sent when a character is pressed in the window focus
(i.e. when the window is topmost). It has two parameters: Char is
a string with length one which only character is the one pressed. Repetition
is integer which says how many times this char was pressed (if you keep
the button down then Repetition can be bigger than one). If you
want to catch a special key like the arrows then use the message key_down.
|key_down(CharCode, Repetition)||this message is sent when a key is pressed in the window focus (i.e.
when the window is topmost). It has two parameters: CharCode is an
integer which is equal to the code of the pressed key. Repetition is integer
which says how many times this key was pressed (if you keep the button
down then Repetition can be bigger than one). See also message_flags.
|key_up(CharCode)||The same as key_down message with the difference that it is sent when the key is released. Also key_up does not have a Repetition parameter.
|mouse clicked at coordinates X, Y inside the client area. There are four messages, respectively for left and right mouse button and for down and up click. Here r_ stands for right button and _up stands for releasing the key. See also message_flags.
|mouse_move(X, Y)||The mouse is moved and the new coordinates are X, Y (in the client area). See also message_flags.
|mouse_wheel(Delta, X, Y)||The mouse wheel is rotated on Delta steps. This message is sent to the window which has the focus even if the mouse cursor is out of the client area of the window. X and Y are the current coordinates of the mouse cursor (in the screen). Coordinates X, Y are given toward to the upper left corner of the screen. Use the predicate client if you want to transfer screen coordinates to the coordinates in the client area.
See also message_flags.
|press||this message is sent to a button or to menu item when it was pressed.
|end||send after the end of the timer's period. See also set_timer.
|edit(Item,Text)||this message is sent to a list box or to a tree box when some one edited
a label in this box. If you want to accept the changes made by the user
then the predicate processing this message should to made this change.
For this purpose it receives the new Text and the Item which is changed.
This message can be send only if you set to the box the style "in place
edit". See also list_box and tree_box.
Note: if you do not want to process the messages to some given window, a predicate with no clauses for it should be declared as the window's function (e.g. fail(_) ).
Note: after the processing of any message the stack is released in the same way as if the code was ended with: !, fail.
Look at the example:
Fractals.pro (in folder Programs)