ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Standard functions / Process functions / Threads, semaphores, signals and mutex
  • Overview
  • Opening a window from a secondary thread via a dialog by messages
  • Principle
  • Example
  • The above-mentioned method is used in the example named WD Instant messaging.
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
A secondary thread cannot directly open a window with the standard WLanguage functions such as: Open, Use, etc.
Nevertheless, you may want to display a window from a secondary thread. For example, if a thread is used to manage some incoming calls, a window containing the characteristics of the caller can be displayed by this thread when an incoming call is detected.
The solution consists in opening the window from a code run by the main thread.
The following methods can be used to execute the code of the main thread from a secondary thread:
  • Run a global procedure of the project or a local procedure of a window via ExecuteMainThread,
  • Run the "Request for refreshing the display" event of a window via RequestRefreshUI,
  • Establish a dialog via messages between threads (PostMessage and Event).
Opening a window from a secondary thread via a dialog by messages

Principle

To open a window from a secondary thread:
  1. When the secondary thread wants to open a window, it sends a message to the main thread with PostMessage. This message indicates to the main thread the window that must be opened as well as the parameters required to open the window.
  2. The main thread manages a specific event, corresponding to the request for window opening. When this event occurs, the WLanguage procedure opens the specified window (with Open up for example) with the specified parameters.
Example

The above-mentioned method is used in the example named WD Instant messaging.

The code for opening the main window is used to:
  • implement an event to manage the opening of the window in the main thread.
  • trigger the secondary threads.
// Mise en place d'un événement 
// pour gérer l'ouverture de la fenêtre de "chat"
gnIdEvenement = Event("OuvertureChat", "*.*", "DebutChat")
IF gnIdEvenement = 0 THEN
	// Erreur lors de la mise en place 
	// de l'événement de gestion de la fenêtre de "chat"
	Error("Impossible de gérer la fenêtre d'ouverture de chat", ErrorInfo())
	// L'application ne peut pas fonctionner sans cet événement
	EndProgram()
END

// Ecoute des requêtes de connexion et de tests de présence
ThreadExecute("ThreadPresence", threadNormal, "EcouteDemandePresence")
ThreadExecute("ThreadRequete", threadNormal, "EcouteDemandeConnexion")
The window is opened in the code of the ListenRequestStartMessage procedure for example. This procedure is run in a thread. The code used to open the window from the thread is as follows:
// Demande d'ouverture de la fenêtre de "chat" 
PostMessage(Handle(FEN_Principale),"DebutChat", FIC_CONTACT.IDCONTACT, FIC_CONTACT.IDCONTACT)
The "ChatStart" message is sent to the main window (identified by its handle). This message contains the different parameters that must be passed to the window. The message is handled by the event defined in the opening code of the window. When the message occurs, the "ChatOpening" procedure is automatically run. This procedure is used to open the window.
The code of this procedure is as follows:
PROCEDURE OuvertureChat(nParam,nContact)
OpenSister(FEN_Message, nContact)


Related Examples:
WD Live Messaging Complete examples (WINDEV): WD Live Messaging
[ + ] This example presents the "Socket" functions of WINDEV.
The following topics are presented in this example:
1/ How to connect to a socket
2/ How to create a socket
Summary of the example supplied with WINDEV:
This example present the different functions for socket management supplied with WINDEV. To use this example, a list of contacts must be entered in your address book. The contacts must be identified by a name and the IP address of their computer. When the application is started, the program searches for the accessible contacts (which means the ones who have started this application on their computer). When you double-click a "connected" contact, a discussion window is opened, giving you the ability to communicate with the contact
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/07/2024

Send a report | Local help