xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Public Attributes | Public Member Functions | Protected Member Functions | List of all members
xtd::forms::application_context Class Reference

#include <application_context.h>

Definition

Specifies the contextual information about an application thread.

Namespace
xtd::forms
Library
xtd.forms
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.
Examples
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);
}
application_context()=default
Initializes a new instance of the application_context class with no context.
static void run()
Begins running a standard application message loop on the current thread, without a form.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13

Inherits xtd::object.

Public Attributes

event< application_context, event_handlerthread_exit
 Occurs when the message loop of the thread should be terminated, by calling exit_thread(). More...
 

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...
 
formmain_form ()
 Gets or sets the Form to use as context. More...
 
const formmain_form () const
 Gets 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 Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 
virtual xtd::ustring to_string () const noexcept
 Returns a std::string that represents the current object. More...
 

Protected Member Functions

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

Additional Inherited Members

- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Constructor & Destructor Documentation

◆ application_context() [1/2]

xtd::forms::application_context::application_context ( )
default

Initializes a new instance of the application_context class with no context.

◆ application_context() [2/2]

xtd::forms::application_context::application_context ( const form main_form)
inlineexplicit

Initializes a new instance of the application_context class with the specified Form.

Parameters
main_formThe main form of the application to use for context.
Remarks
If on_main_form_closed is not overridden, the message loop of the thread terminates when main_form is closed.

Member Function Documentation

◆ exit_thread()

void xtd::forms::application_context::exit_thread ( )
inline

Terminates the message loop of the thread.

Remarks
This method calls exit_thread_core.
Note
exit_thread and exit_thread_core do not actually cause the thread to terminate. These methods raise the thread_exit event to which the Application object listens. The Application object then terminates the thread.

◆ exit_thread_core()

virtual void xtd::forms::application_context::exit_thread_core ( )
inlineprotectedvirtual

Terminates the message loop of the thread.

Remarks
This method is called from exit_thread.
Note
exit_thread and exit_thread_core do not actually cause the thread to terminate. These methods raise the thread_exit event to which the Application object listens. The Application object then terminates the thread.

◆ main_form() [1/3]

form& xtd::forms::application_context::main_form ( )
inline

Gets or sets the Form to use as context.

Returns
The form to use as context.
Remarks
This property determines the main form for this context. This property can change at any time. If on_main_form_closed is not overridden, the message loop of the thread terminates when the main_form parameter closes.

◆ main_form() [2/3]

const form& xtd::forms::application_context::main_form ( ) const
inline

Gets the form to use as context.

Returns
The form to use as context.
Remarks
This property determines the main form for this context. This property can change at any time. If on_main_form_closed is not overridden, the message loop of the thread terminates when the main_form parameter closes.

◆ main_form() [3/3]

void xtd::forms::application_context::main_form ( const form main_form)
inline

Sets the Form to use as context.

Parameters
main_formThe form to use as context.
Remarks
This property determines the main form for this context. This property can change at any time. If on_main_form_closed is not overridden, the message loop of the thread terminates when the main_form parameter closes.

◆ on_main_form_closed()

virtual void xtd::forms::application_context::on_main_form_closed ( object sender,
const event_args e 
)
inlineprotectedvirtual

Calls ExitThreadCore(), which raises the ThreadExit event.

Parameters
senderThe object that raised the event.
eThe event_args that contains the event data.
Remarks
The default implementation of this method calls exit_thread_core.

◆ tag() [1/2]

std::any xtd::forms::application_context::tag ( ) const
inline

Gets an object that contains data about the control.

Returns
A std::any that contains data about the control. The default is empty.
Remarks
Any type of class can be assigned to this property.
A common use for the tag property is to store data that is closely associated with the control. For example, if you have a control that displays information about a customer, you might store a data_set that contains the customer's order history in that control's tag property so the data can be accessed quickly.

◆ tag() [2/2]

void xtd::forms::application_context::tag ( std::any  tag)
inline

Sets an object that contains data about the control.

Parameters
tagA std::any that contains data about the control. The default is empty.
Remarks
Any type of class can be assigned to this property.
A common use for the tag property is to store data that is closely associated with the control. For example, if you have a control that displays information about a customer, you might store a data_set that contains the customer's order history in that control's tag property so the data can be accessed quickly.

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