xtd - Reference Guide  0.1.0
Modern c++17 framework to create console, gui and unit test applications on Windows, macOS and Linux.
xtd::forms::application_context Class Reference

Specifies the contextual information about an application thread. More...

#include <application_context.h>

Public Member Functions

 application_context ()=default
 Initializes a new instance of the application_context class with no context. More...
 
 application_context (const form &main_form)
 Initializes a new instance of the application_context class with the specified Form. More...
 
void exit_thread ()
 Terminates the message loop of the thread. More...
 
const formmain_form () const
 Gets the form to use as context. More...
 
formmain_form ()
 Gets or sets the Form to use as context. More...
 
void main_form (const form &main_form)
 Sets the Form to use as context. More...
 
std::any tag () const
 Gets an object that contains data about the control. More...
 
void tag (std::any tag)
 Sets an object that contains data about the control. More...
 

Public Attributes

event< application_context, event_handler< const application_context & > > thread_exit
 Occurs when the message loop of the thread should be terminated, by calling exit_thread(). More...
 

Protected Member Functions

virtual void exit_thread_core ()
 Terminates the message loop of the thread. More...
 
virtual void on_main_form_closed (const control &sender, const event_args &e)
 Calls ExitThreadCore(), which raises the ThreadExit event. More...
 

Detailed Description

Specifies the contextual information about an application thread.

Remarks
You can use the application_context class to redefine the circumstances that cause a message loop to exit. By default, the application_context listens to the closed event on the application's main form, then exits the thread's message loop.
Example
The following code example demonstrate the use of application and application_context classes.
#include <xtd/xtd>
using namespace xtd::forms;
int main() {
form form1;
form1.click += [&] {
context.main_form(form1);
};
form1.text("Form 1 (Click the client area to set form as the main form)");
form1.show();
form form2;
form2.click += [&] {
context.main_form(form2);
};
form2.text("Form 2 (Click the client area to set form as the main form)");
form2.show();
form form3;
form3.click += [&] {
context.main_form(form3);
};
form3.text("Form 3 (Click the client area to set form as the main form)");
form3.show();
// if no client area form clicked, the application will not exit when you close the forms.
application::run(context);
}

The documentation for this class was generated from the following file: