Home | Sign in | English UK
  • This lesson will teach you the following concepts
  • Introduction
  • Practical example
  • Optional events proposed by WINDEV
  • Windows events
  • Example : Detect the click on a list
Lesson 7.5. Windows event
This lesson will teach you the following concepts
  • Programming the Windows events.

Estimated time: 10 mn
Previous LessonTable of contentsNext Lesson
Each action performed by Windows corresponds to a Windows event. Different types of events can occur, for example:
  • A window is hovered by the mouse,
  • The system is stopped,
  • A dialog box is displayed,
  • A software error,
  • Etc.
When these events occur, they can be intercepted in order to prepare or to run a specific process.
WINDEV proposes an automatic management of most common events. For example, the following events are proposed for an edit control:
  • Initializing the control,
  • Entry in the control,
  • Modifying the control,
  • Exit from the control.
To manage additional events, you can:
  • use the optional events proposed by WINDEV.
  • use the Windows events.

Practical example

The management of events will be presented via the unit example named "The Event function".
  • Open the unit example named "The Event function".
Optional events proposed by WINDEV
WINDEV proposes many optional events for each element (window, control, etc.).
  • To add an optional event:
    1. Display the events related to the List Box control in the unit example window:
      • Select the List Box control.
      • Press the F2 key.
      • The code editor is displayed.
    2. Click the "Add other processes..." linkClick the "Add other events..." link:
    3. The complete list of available optional events is displayed:
    4. To add an event, simply check the corresponding box and validate this window. Add the "Key Pressed" event for example.
Windows events
To manage more "specific" events, you have the ability to use the WLanguage Event function. Event is used to associate a WLanguage procedure to a Windows event.


To use Event, you must be familiar with the Windows programming, especially the Windows events.

To find out the non-exhaustive list of Windows events, see Value of constants for the Windows 32-bit API.

Example : Detect the click on a list

  • Run the test of "WIN_Event_Function" window. This window detects if the list is manipulated with the mouse or with the keyboard.
    1. Click the List Box control with the mouse.
    2. Use the mouse to move the selection bar.
    3. A message is displayed, specifying whether the mouse or the keyboard was used.
    4. Stop the test and go back to the editor.
  • Let's study the code used:
    1. Click in the window.
    2. Display the window events (press F2).
    3. Let's study the declaration code of global variables of WIN_Event_Function window.
      • First of all, the code line:
        This code line is used to include the content of WINCONST.WL file in the application code via the EXTERN keyword. This file contains the declaration and values of Windows constants. During the compilation, the entire code found in the WINCONST.WL file will be automatically included in the application code.
      • Then, all supported events are declared:
        // Events on LIST_Month control
        // Keyboard key down
        Event("MouseOrKeyboard", LIST_Month..FullName, WM_KEYDOWN)
        // Left mouse click
        Event("MouseOrKeyboard", LIST_Month..FullName, WM_LBUTTONDOWN)
        The procedure MouseOrKeyboard is called whenever the keyboard is used on the list (corresponding Windows event: WM_KEYDOWN) or whenever the left mouse click is used (corresponding Windows event: WM_LBUTTONDOWN).
    4. Display the procedure code:
      • Position the mouse cursor on "MouseOrKeyboard".
      • Press the F2 key.
    5. The procedure code is straightforward:
      • If the keyboard is used, the caption displayed below the List Box control contains "Selection with the keyboard".
      • If the mouse is used, the caption displayed below the List Box control contains "Selection with the mouse".
        PROCEDURE MouseOrKeyboard()
        // The _EVE.wMessage variable contains the message number
        SWITCH _EVE.wMessage
        // Keyboard
        // Message indicating that the keyboard is used
        STC_SelectionType = "Selection with the keyboard"
        STC_SelectionType..Color = LightRed

        // It's the mouse
        // Message indicating that the mouse is used
        STC_SelectionType = "Selection with the mouse"
        STC_SelectionType..Color = LightBlue
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 24
Click [Add] to post a comment