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
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Overview
A secondary thread cannot directly open a window using classic WLanguage functions such as: Open, Use, ...
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).
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
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 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.
// Implement an event 
// to manage the opening of the "chat" window
gnEventID = Event("ChatOpening", "*.*", "ChatStart")
IF gnEventID = 0 THEN
	// Error when implementing 
	// the event used to manage the "chat" window
	Error("Unable to manage the window for chat opening", ErrorInfo())
	// The application cannot operate without this event
	EndProgram()
END

// Listen to connection requests and presence tests
ThreadExecute("ThreadPresence", threadNormal, "ListenPresenceRequest")
ThreadExecute("ThreadRequest", threadNormal, "ListenConnectionRequest")
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:
// Ask to open the "chat" window 
PostMessage(Handle(WIN_Main),"ChatStart", FILE_CONTACT.CONTACTID, FILE_CONTACT.CONTACTID)
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 ChatOpening(nParam,nContact)
OpenSister(WIN_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: 09/30/2024

Send a report | Local help