ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

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 RequestUpdateUI,
  • 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 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 the requests for connection and for 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)
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/21/2023

Send a report | Local help