xtd 0.2.0
application_restart.cpp

Shows how to create an application with xtd::forms::application::restart method.

Windows

macOS

Gnome

#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/environment>
using namespace xtd;
using namespace xtd::forms;
auto main() -> int {
auto restart_count = environment::get_environment_variable("application_restart_count").empty() ? 0 : parse<int>(environment::get_environment_variable("application_restart_count"));
auto main_form = form::create(string::format("Restart {} times", restart_count));
auto restart_button = button::create(main_form, "Restart", {10, 10});
restart_button.click += application::restart;
environment::set_environment_variable("application_restart_count", int32_object {restart_count + 1}.to_string());
application::run(main_form);
}
static void set_environment_variable(const xtd::string &variable, const xtd::string &value)
Creates, modifies, or deletes an environment variable stored in the current process.
static xtd::string get_environment_variable(const xtd::string &variable)
Retrieves the value of an environment variable from the current process.
static void run()
Begins running a standard application message loop on the current thread, without a form.
static void restart()
Shuts down the application and starts a new instance immediately.
static button create()
A factory to create an xtd::forms::button.
static form create()
A factory to create an xtd::forms::form.
box_integer< int32 > int32_object
Represent a boxed int32.
Definition int32_object.hpp:29
value_t parse(const std::string &str)
Convert a string into a type.
Definition parse.hpp:34
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8