PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
New WINDEV 28 feature!
  • In this lesson you will learn the following concepts
  • Introduction
  • Practical example
  • Optional events available in WINDEV
  • Windows events
  • Example : Detect the click on a List Box control
Lesson 7.5. Windows event
In this lesson you will learn the following concepts
  • Programming Windows events.
Lesson duration

Estimated time: 10 mn
Previous LessonTable of contentsNext Lesson
Introduction
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 run a specific process.
WINDEV can automatically manage the most common events. For example, the following events are available by default for Edit controls:
  • Initialize the control,
  • Entry in the control,
  • Modify the control,
  • Exit the control.
To handle additional events, you can:
  • use the optional events available in 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 available in WINDEV
WINDEV includes multiple optional events for each element (window, control, etc.).
  • To add an optional event:
    1. Display the WLanguage events associated to the List Box control in the unit example window:
      • Select the List Box control.
      • Press F2.
      • The code editor is displayed.
    2. Click the "Add other events..." link:
      Link 'Add other events'
    3. The complete list of available optional events is displayed:
      List of optional events
    4. To add an event, simply check the corresponding box and validate the window. For example, add the "Key down" event and validate the window.
Windows events
To add more "specific" events, you can use the Event WLanguage function. Event is used to associate a WLanguage procedure to a Windows event.

Note

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

To get the (non-exhaustive) list of Windows events, see Value of constants for the Windows 32-bit API.

Example : Detect the click on a List Box control

  • Test the "WIN_Event_Function" window. This window detects if the List Box control is manipulated with the mouse or with the keyboard.
    1. Click the List Box control.
    2. Use the mouse to move the selection bar.
    3. A message is displayed, specifying whether the mouse or the keyboard was used.
      Window test
    4. Stop the test and go back to the editor.
  • Let's take a look at the code used:
    1. Click in the window.
    2. Open the window events (press F2).
    3. Let's take a look at the "Global declarations" event of "WIN_Event_Function".
      • First of all, the following line of code:
        EXTERN "WINCONST.WL"
        This line of code is used to include the content of the WINCONST.WL file in the application code via the EXTERN keyword. This file contains the declaration and values of the Windows constants. During the compilation, the code from the WINCONST.WL file will be automatically included in the application code.
      • Then, all supported events are declared:
        // Events on the LIST_Months control
        // Keyboard key down
        Event(MouseOrKeyboard, LIST_Months.FullName, WM_KEYDOWN)
        // Left mouse click
        Event(MouseOrKeyboard, LIST_Months.FullName, WM_LBUTTONDOWN)
        The MouseOrKeyboard procedure is called when the keyboard is used on the List control (corresponding Windows event: WM_KEYDOWN) or when the left mouse button is pressed (corresponding Windows event: WM_LBUTTONDOWN).
    4. The MouseOrKeyboard procedure is an internal procedure. The code of this procedure is right after the "Global declarations" event.. This code is very simple:
      • 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".
        INTERNAL PROCÉDURE MouseOrKeyboard()
        // The _EVE.wMessage variable contains the message number
        SWITCH _EVE.wMessage
        // Keyboard
        CASE WM_KEYDOWN
        // Message indicating that the keyboard is used
        STC_SelectionType = "Selection with the keyboard"
        STC_SelectionType.Color = LightRed
         
        // It's the mouse
        CASE WM_LBUTTONDOWN
        // Message indicating that the mouse is used
        STC_SelectionType = "Selection with the mouse"
        STC_SelectionType.Color = LightBlue
        END
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 28
Comments
Click [Add] to post a comment