Skip to content

How to create application and run the message loop ?

Gammasoft edited this page Nov 12, 2023 · 5 revisions

| xtd | News | Gallery | Examples | Downloads | Documentation | Wiki | Support | Sources | Project | Gammasoft |

The application is a static class. The "application" is created when one of the run member methods is called, and destroyed when the method is exited.

The message loop is started too when one of the run member methods is called, and stopped when the method is exited.

Remarks

To exit the message loop, you must either call the application's exit or exit_thread method, or close the main form.

Create an application without form

Call the run method without argument.

#include <xtd/forms/application>

using namespace xtd::forms;

auto main()->int {
  application::run();
}

Create an application without main form

Create a form, show it and call the run method without argument.

#include <xtd/forms/application>

using namespace xtd::forms;

auto main()->int {
  auto form1 = form {};
  form1.text("My first application");
  form1.show();
  application::run();
}

Create application with a main form

Simply create a form and pass it as a parameter to the run method.

#include <xtd/forms/application>

using namespace xtd::forms;

auto main()->int {
  auto form1 = form {};
  form1.text("My first application");
  application::run(form1);
}

Create application with application_context and a main form

Create a form and an application_context. Use the application_context as parameter of the application run method.

The application_context is used to modify the main form at any time. In fact, the main_form property is used to modify the main form or simply not to designate one.

#include <xtd/forms/application>

using namespace xtd::forms;

auto main()->int {
  auto form1 = form {};
  form1.text("My first application");
  
  auto context = application_context {form1};
  
  application::run(context);
}

See