|
|
|
|
- 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.
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:
- 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.
- Click the "Add other events..." link:
- The complete list of available optional events is displayed:
- To add an event, simply check the corresponding box and validate the window. For example, add the "Key down" event and validate the window.
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.
- Click the List Box control.
- Use the mouse to move the selection bar.
- A message is displayed, specifying whether the mouse or the keyboard was used.
- Stop the test and go back to the editor.
- Let's take a look at the code used:
- Click in the window.
- Open the window events (press F2).
- Let's take a look at the "Global declarations" event of "WIN_Event_Function".
- First of all, the following line of code:
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).
- 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|