### Create and Run xtd Console Application Source: https://github.com/gammasoft71/xtd/blob/master/docs/hello_world.md Commands to create a new xtd console application named 'sample1' and then run it. This demonstrates the basic workflow for starting an xtd project. No external dependencies are required beyond the xtd installation. ```shell xtdc new console sample1 xtdc run sample1 ``` -------------------------------- ### Install xtd on Windows Source: https://github.com/gammasoft71/xtd/blob/master/docs/downloads.md This shell command initiates the installation of xtd on Windows after the necessary prerequisites (Microsoft Visual Studio and CMake) have been installed. Navigate to the xtd directory in the Command Prompt and execute the 'install' command. This process builds and installs the framework for use in your applications. ```shell cd xtd_path_name install ``` -------------------------------- ### Enumerate Directories using directory::enumerate_directories (C++) Source: https://github.com/gammasoft71/xtd/blob/master/docs/common_io_tasks_enumerate_directories_and_files.md This example shows how to use the directory::enumerate_directories method to get a list of top-level directory names in a specified path. It handles potential unauthorized access and path too long exceptions. ```cpp #include using namespace xtd; using namespace xtd::collections::generic; using namespace xtd::io; class program { public: static auto main() { try { // Set a variable to the My Documents path. string doc_path = environment::get_folder_path(environment::special_folder::my_documents); auto dirs_iterator = directory::enumerate_directories(doc_path); list dirs(dirs_iterator.begin(), dirs_iterator.end()); for (auto dir : dirs) { console::write_line("{}", dir.substring(dir.last_index_of(path::directory_separator_char()) + 1)); } console::write_line("{} directories found.", dirs.count()); } catch (const unauthorized_access_exception& ex) { console::write_line(ex.message()); } catch (const path_too_long_exception& ex) { console::write_line(ex.message()); } } }; startup_(program::main); ``` -------------------------------- ### Create Test Fixture and Cases with Helpers in C++ Source: https://github.com/gammasoft71/xtd/blob/master/docs/writing_applicaion_test.md This example shows how to define a test fixture and its associated test cases using helper macros provided by xtd.tunit. It includes setup and cleanup methods for the class and individual tests. This approach simplifies the registration of test components. ```cpp #include using namespace xtd::tunit; namespace unit_tests { // Create new test fixture with test_class_ helper. class test_class_(test) { public // This method is called 1 time before test class run static void class_initialize_(class_initialize) { } // This method is called 1 time after test class run static void class_cleanup_(class_cleanup) { } // This method that is called before each test case of test fixture. static void test_initialize_(test_initialize) { } // This method is called after each test case of test fixture. static void test_cleanup_(test_cleanup) { } // Test case 1 void test_method_(test_case1) { } // Test case 2 void test_method_(test_case2) { } // Ignore Test case 3 void ignore_test_method_(test_case3) { } }; } auto main(int argc, char* argv[]) -> int { return console_unit_test(argv, argc).run(); } ``` -------------------------------- ### Get OS Desktop Environment using xtd::environment Source: https://github.com/gammasoft71/xtd/blob/master/docs/ebook_console_classes.md Shows how to retrieve the desktop environment information of the operating system using xtd::environment::os_version().desktop_environment(). This example also demonstrates string joining with xtd::strings::join. ```cpp #include #include auto main(int argc, char* argv[]) -> int { auto str1 = xtd::environment::os_version().desktop_environment(); auto str2 = "desktop"_s; auto str3 = "environment"_s; xtd::console::write_line(xtd::strings::join(" ", {str1, str2, str3})); } ``` -------------------------------- ### Build and Run Project with xtdc Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.core.examples/text/README.md Shows the command-line interface command to build and run any xtd project. This is a fundamental step for developing and testing applications using the xtd framework. It requires the 'xtdc' tool to be installed and accessible in the system's PATH. ```shell # Navigate to your project folder in the terminal or command prompt # Then run the following command: xtdc run -t any_project_name ``` -------------------------------- ### Hello World Console Application (C++) Source: https://github.com/gammasoft71/xtd/blob/master/docs/doxygen/doxygen/main_page.dox A basic 'Hello World' console application using the xtd framework. It demonstrates setting console colors and writing output. This example requires the xtd library and CMake build system. ```cpp #include using namespace xtd; auto main() -> int { console::background_color(console_color::blue); console::foreground_color(console_color::white); console::write_line("Hello, World!"); } ``` ```cmake cmake_minimum_required(VERSION 3.20) project(hello_world_console) find_package(xtd REQUIRED) add_sources(hello_world_console.cpp) ``` -------------------------------- ### Generate Entry Point with TUNIT_CONFIG_MAIN (C++) Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.tunit.examples/others/tunit_config_main/README.md This snippet shows how to use the TUNIT_CONFIG_MAIN macro to automatically generate the main function for a C++ application using the xtd unit testing framework. It requires the 'xtd.h' header. The macro handles the setup and execution of tests. ```cpp #include TUNIT_CONFIG_MAIN; ``` -------------------------------- ### Split Container Example (C++) Source: https://github.com/gammasoft71/xtd/blob/master/docs/doxygen/doxygen/xtd_forms_examples.dox Illustrates the use of the xtd::forms::split_container container for creating resizable panels. This example is functional on Windows, macOS, and Gnome. ```cpp /// demonstrates the use of xtd::forms::split_container container. /// @par Windows /// @image html split_container_w.png ///
/// @image html split_container_wd.png /// @par macOS /// @image html split_container_m.png ///
/// @image html split_container_md.png /// @par Gnome ``` -------------------------------- ### GUID Tests Source: https://github.com/gammasoft71/xtd/blob/master/tests/xtd.core.unit_tests/CMakeLists.txt This test suite validates the functionality related to Globally Unique Identifiers (GUIDs), including generation and comparison. ```cpp #include #include namespace xtd::tests { class guid_tests : public tunit::test { public: static void test_main() { xtd::guid g1; xtd::guid g2 = xtd::guid::empty_guid(); assert::is_false(g1.is_empty()); assert::is_true(g2.is_empty()); assert::is_not_equal(g1, g2); } }; } ``` -------------------------------- ### C++ form_and_main using startup_ keyword Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.forms.examples/others/form_and_main/README.md This C++ code demonstrates the 'startup_' keyword from the xtd library. It likely defines the main entry point for an application, potentially involving form or window creation. No external dependencies beyond the xtd library are explicitly mentioned. The output would be the execution of the application. ```cpp #include int main(int argc, char** argv) { xtd::forms::application::run(xtd::forms::form {}); } ``` -------------------------------- ### C++: startup_ with static int main(int, char*[]) Source: https://github.com/gammasoft71/xtd/blob/master/docs/main_and_startup.md This example demonstrates `startup_` with a static `main` function that accepts C-style integer and character pointer array arguments and returns an integer. It logs the arguments and returns an exit status. ```cpp #include using namespace xtd; namespace examples { class program { public: static auto main(int argc, char* argv[]) -> int { // Write arguments to the console output for (auto arg : {argv, argv + argc}) console::write_line(arg); return 42; } }; } startup_(examples::program::main); ``` -------------------------------- ### xtd Forms Input Dialog Password Example Source: https://github.com/gammasoft71/xtd/blob/master/docs/doxygen/doxygen/xtd_forms_examples.dox This C++ example demonstrates how to use xtd::forms::input_dialog to securely get password input from the user. The dialog masks the entered characters, providing a secure way to handle sensitive information. ```cpp #include int main() { xtd::forms::form form; form.text("Input Dialog Password Example"); xtd::forms::input_dialog dialog; dialog.title("Enter Password"); dialog.password(true); dialog.buttons("OK", "Cancel"); if (dialog.show_dialog() == xtd::forms::dialog_result::ok) { xtd::forms::message_box::show(form, "Password entered (hidden).", "Password Input"); } xtd::forms::application::run(form); } ``` -------------------------------- ### Install and Initialize Doxygen Awesome Tabs Source: https://github.com/gammasoft71/xtd/blob/master/docs/doxygen/doxygen-awesome-css/docs/extensions.md Guide to installing and initializing the Doxygen Awesome Tabs extension. Requires adding the JavaScript file to Doxyfile and header.html, followed by calling DoxygenAwesomeTabs.init(). ```html ``` -------------------------------- ### Application Settings Example (C++) Source: https://github.com/gammasoft71/xtd/blob/master/docs/doxygen/doxygen/xtd_forms_examples.dox Demonstrates the use of the xtd::settings component without CMake setting commands. This example shows how to manage application settings, with visual output for Windows, macOS, and Gnome. ```cpp #include #include int main() { // Example of using settings - actual code would go here std::cout << "Demonstrating xtd::settings component." << std::endl; // xtd::settings::set_string("MyKey", "MyValue"); // std::cout << "Value: " << xtd::settings::get_string("MyKey") << std::endl; return 0; } ``` -------------------------------- ### xtd Unit Test Example Source: https://github.com/gammasoft71/xtd/blob/master/docs/doxygen/doxygen/main_page.dox A C++ unit test example using xtd's tunit framework. It includes tests for string manipulation and assertions. Requires a CMakeLists.txt file to build. ```cpp #include using namespace xtd; using namespace xtd::tunit; namespace unit_tests { class test_class_(hello_world_test) { void test_method_(create_string_from_literal) { string s = "Hello, World!"; assert::are_equal("Hello, World!", s); } void test_method_(create_string_from_chars) { string s = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'}; valid::are_equal(13, s.length()); string_assert::starts_with("Hello,", s); string_assert::ends_with(" World!", s); } }; } auto main() -> int { return console_unit_test(argv, argc).run(); } ``` ```cmake cmake_minimum_required(VERSION 3.20) project(hello_world_test) find_package(xtd REQUIRED) add_sources(hello_world_test.cpp) target_type(TEST_APPLICATION) ``` -------------------------------- ### C++: startup_ with static int main(const argument_collection&) Source: https://github.com/gammasoft71/xtd/blob/master/docs/main_and_startup.md This example shows `startup_` with a static `main` function that accepts an `argument_collection` and returns an integer. It logs the arguments and returns an exit status. ```cpp #include #include using namespace xtd; using namespace xtd::collections::generic; namespace examples { class program { public: static auto main(const argument_collection& args) -> int { // Write arguments to the console output for (auto arg : args) console::write_line(arg); return 42; } }; } ``` -------------------------------- ### Get Operating System Version using xtd::version Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.core.examples/version/README.md This example demonstrates how to utilize the xtd::version class to retrieve the version information of the current Operating System. It shows a practical application of the xtd::version class for system introspection. ```c++ #include #include int main() { xtd::version os_version = xtd::version::os_version(); std::cout << "Operating System Version: " << os_version << std::endl; return 0; } ``` -------------------------------- ### Build and Run Console Application Source: https://github.com/gammasoft71/xtd/blob/master/README.md Instructions for building and running the 'hello_world_console' application using the 'xtdc run' command. This assumes the project is set up with CMake and the xtdc tool is available in the environment. ```shell xtdc run ``` -------------------------------- ### xtd Console Application Hello World Source: https://github.com/gammasoft71/xtd/blob/master/docs/doxygen/doxygen/main_page.dox A simple C++ console application that prints 'Hello, World!' to the console. This example demonstrates basic output. ```cpp #include using namespace xtd::forms; class main_form : public form { public: main_form() { text("Hello world (message_box)"); button1.location({10, 10}); button1.parent(*this); button1.text("&Click me"); button1.click += [] { message_box::show("Hello, World!"); }; } private: button button1; }; auto main() -> int { application::run(main_form()); } ``` -------------------------------- ### Basic Form Container Usage in C++ Source: https://github.com/gammasoft71/xtd/blob/master/docs/doxygen/doxygen/xtd_forms_examples.dox This C++ code provides a fundamental example of creating and displaying a basic form using the `xtd::forms::form` container. It serves as a starting point for building graphical user interfaces with the xtd framework. The code initializes the application and runs the main form. ```cpp #include #include using namespace xtd; using namespace xtd::forms; int main() { // Create a new form instance auto main_form = form::create("My First Form"); main_form.size({400, 300}); // Set the size of the form // Run the application with the main form application::run(main_form); } ``` -------------------------------- ### Demonstrate xtd Window States with C++ Source: https://github.com/gammasoft71/xtd/blob/master/docs/form.md This C++ code example demonstrates how to set and manage different window states for an xtd form, including normal, minimized, maximized, and full-screen. It utilizes buttons to trigger state changes and updates button enabled states based on the current window state. The example requires the xtd.forms library. ```cpp #include using namespace xtd; using namespace xtd::forms; class form1 : public form { public: form1() { *this << button_full_screen << button_maximize << button_minimize << button_normal; text("Window state example"); resize += [&] { button_full_screen.enabled(window_state() != form_window_state::full_screen && window_state() != form_window_state::maximized); button_maximize.enabled(window_state() != form_window_state::maximized && window_state() != form_window_state::full_screen); button_normal.enabled(window_state() != form_window_state::normal); button_minimize.enabled(window_state() != form_window_state::minimized && window_state() != form_window_state::full_screen); ctrace << string::format("resize: {}, {}", size(), window_state()) << std::endl; }; client_size({410, 200}); window_state(form_window_state::maximized); button_full_screen.location({10, 10}); button_full_screen.text("Full screen"); button_full_screen.width(90); button_full_screen.click += [&] { window_state(form_window_state::full_screen); }; button_maximize.location({110, 10}); button_maximize.text("Maximize"); button_maximize.width(90); button_maximize.click += [&] { window_state(form_window_state::maximized); }; button_normal.location({210, 10}); button_normal.text("Normal"); button_normal.width(90); button_normal.click += [&] { window_state(form_window_state::normal); }; button_minimize.location({310, 10}); button_minimize.text("Minimize"); button_minimize.width(90); button_minimize.click += [&] { window_state(form_window_state::minimized); }; } private: button button_full_screen; button button_maximize; button button_normal; button button_minimize; }; auto main() -> int { application::run(form1 {}); } ``` -------------------------------- ### Start xtd Application Event Loop Without Main Form Source: https://github.com/gammasoft71/xtd/blob/master/docs/application_overview.md This example shows how to start the xtd application event loop without an initial main form. Unlike the version with a specified form, this application will not automatically exit when a window is closed. You must explicitly call application::exit() or application::exit_thread() to terminate the application. ```cpp #include using namespace xtd::forms; auto main() -> int { form form1; form1.show(); form1.form_closed += [] { // If you comment the following line the application will not exit when you close the form. application::exit(); }; application::run(); } ``` -------------------------------- ### Console Hello World in C++ with CMake Source: https://github.com/gammasoft71/xtd/blob/master/docs/examples.md Demonstrates a basic 'Hello World' application for the console using xtd. It includes the C++ source code and the CMakeLists.txt file for building the project. The output is printed to the console. ```cpp #include using namespace xtd; auto main() -> int { console::background_color(console_color::blue); console::foreground_color(console_color::white); console::write_line("Hello, World!"); } ``` ```cmake cmake_minimum_required(VERSION 3.20) project(hello_world_console) find_package(xtd REQUIRED) add_sources(hello_world_console.cpp) target_type(CONSOLE_APPLICATION) ``` -------------------------------- ### GUI Hello World Form in C++ with CMake Source: https://github.com/gammasoft71/xtd/blob/master/docs/examples.md Illustrates how to create a simple graphical user interface (GUI) 'Hello World' application using xtd. This example features a form with a button that, when clicked, displays a message box. It provides both the C++ code and the CMakeLists.txt for compilation. ```cpp #include using namespace xtd::forms; class main_form : public form { public: main_form() { text("Hello world (message_box)"); button1.location({10, 10}); button1.parent(*this); button1.text("&Click me"); button1.click += [] { message_box::show("Hello, World!"); }; } private: button button1; }; auto main() -> int { application::run(main_form()); } ``` ```cmake cmake_minimum_required(VERSION 3.20) project(hello_world_form) find_package(xtd REQUIRED) add_sources(hello_world_form.cpp) target_type(GUI_APPLICATION) ``` -------------------------------- ### Get Know Folder Path Tests Source: https://github.com/gammasoft71/xtd/blob/master/tests/xtd.core.unit_tests/CMakeLists.txt Tests for the utility function that retrieves the path to known system folders. This is essential for accessing standard locations like 'My Documents' or 'Program Files'. ```cpp #include #include namespace xtd::tests { class get_know_folder_path_tests : public tunit::test { public: static void test_main() { // Example test: Check if MyDocuments path can be retrieved xtd::ustring my_documents_path = xtd::io::known_folder::my_documents(); assert::is_not_empty(my_documents_path); // Further assertions could check for expected starting paths based on OS } }; } ``` -------------------------------- ### C++: startup_ with static int main() Source: https://github.com/gammasoft71/xtd/blob/master/docs/main_and_startup.md This example illustrates using `startup_` with a static `main` member function that takes no arguments and returns an integer. The function logs command-line arguments and returns a specific exit code. ```cpp #include using namespace xtd; namespace examples { class program { public: static auto main() -> int { // Write arguments to the console output for (auto arg : environment::get_command_line_args()) console::write_line(arg); return 42; } }; } startup_(examples::program::main); ``` -------------------------------- ### xtd GUI Application Hello World Source: https://github.com/gammasoft71/xtd/blob/master/docs/doxygen/doxygen/main_page.dox A C++ GUI application example using xtd framework. It creates a form with a button that displays a message box when clicked. Requires a CMakeLists.txt file to build. ```cpp #include using namespace xtd::forms; class main_form : public form { public: main_form() { text("Hello world (message_box)"); button1.location({10, 10}); button1.parent(*this); button1.text("&Click me"); button1.click += [] { message_box::show("Hello, World!"); }; } private: button button1; }; auto main() -> int { application::run(main_form()); } ``` ```cmake cmake_minimum_required(VERSION 3.20) project(hello_world_forms) find_package(xtd REQUIRED) add_sources(hello_world_forms.cpp) target_type(GUI_APPLICATION) ``` -------------------------------- ### xtd Date-Time Formatting Examples Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.core.examples/format/format_date_time/README.md Demonstrates various date and time formatting options available in the xtd library. These examples cover different date and time components and presentation styles. ```text date_time {123456789123456789} │ {:u} │ 0392-03-21 19:15:12Z │ date_time {123456789123456789} │ {:U} │ Saturday, March 21, 0392 19:15:12 │ date_time {123456789123456789} │ {:y} │ March 0392 │ date_time {123456789123456789} │ {:Y} │ March 0392 │ date_time {123456789123456789} │ {:h:mm:ss.ff t} │ 7:15:12.34 P │ date_time {123456789123456789} │ {:d MMM yyyy} │ 21 Mar 0392 │ date_time {123456789123456789} │ {:HH:mm:ss.f} │ 19:15:12.3 │ date_time {123456789123456789} │ {:dd MMM HH:mm:ss} │ 21 Mar 19:15:12 │ date_time {123456789123456789} │ {:\Mon\t\h\: M} │ Month: 3 │ date_time {123456789123456789} │ {:HH:mm:ss.ffffzzz} │ 19:15:12.3456+00:17 ├───────────────────────────────────────┼─────────────────────┼──────────────────────────────────────────┤ │ date_time {1971, 1, 5} │ {} │ 1/5/1971 00:00:00 │ date_time {1971, 1, 5} │ {:d} │ 1/5/1971 │ date_time {1971, 1, 5} │ {:D} │ Tuesday, January 5, 1971 │ date_time {1971, 1, 5} │ {:f} │ Tuesday, January 5, 1971 00:00 │ date_time {1971, 1, 5} │ {:F} │ Tuesday, January 5, 1971 00:00:00 │ date_time {1971, 1, 5} │ {:g} │ 1/5/1971 00:00 │ date_time {1971, 1, 5} │ {:G} │ 1/5/1971 00:00:00 │ date_time {1971, 1, 5} │ {:m} │ January 5 │ date_time {1971, 1, 5} │ {:M} │ January 5 │ date_time {1971, 1, 5} │ {:o} │ 1971-01-05T00:00:00.0000000Z │ date_time {1971, 1, 5} │ {:O} │ 1971-01-05T00:00:00.0000000Z │ date_time {1971, 1, 5} │ {:r} │ Tue, 05 Jan 1971 00:00:00 GMT │ date_time {1971, 1, 5} │ {:R} │ Tue, 05 Jan 1971 00:00:00 GMT │ date_time {1971, 1, 5} │ {:s} │ 1971-01-05T00:00:00 │ date_time {1971, 1, 5} │ {:t} │ 00:00 │ date_time {1971, 1, 5} │ {:T} │ 00:00:00 │ date_time {1971, 1, 5} │ {:u} │ 1971-01-05 00:00:00Z │ date_time {1971, 1, 5} │ {:U} │ Tuesday, January 5, 1971 00:00:00 │ date_time {1971, 1, 5} │ {:y} │ January 1971 │ date_time {1971, 1, 5} │ {:Y} │ January 1971 │ date_time {1971, 1, 5} │ {:h:mm:ss.ff t} │ 0:00:00.00 A │ date_time {1971, 1, 5} │ {:d MMM yyyy} │ 5 Jan 1971 │ date_time {1971, 1, 5} │ {:HH:mm:ss.f} │ 00:00:00.0 │ date_time {1971, 1, 5} │ {:dd MMM HH:mm:ss} │ 05 Jan 00:00:00 │ date_time {1971, 1, 5} │ {:\Mon\t\h\: M} │ Month: 1 │ date_time {1971, 1, 5} │ {:HH:mm:ss.ffffzzz} │ 00:00:00.0000+01:00 ├───────────────────────────────────────┼─────────────────────┼──────────────────────────────────────────┤ │ date_time {1971, 1, 5, 21, 30, 3} │ {} │ 1/5/1971 21:30:03 │ date_time {1971, 1, 5, 21, 30, 3} │ {:d} │ 1/5/1971 │ date_time {1971, 1, 5, 21, 30, 3} │ {:D} │ Tuesday, January 5, 1971 │ date_time {1971, 1, 5, 21, 30, 3} │ {:f} │ Tuesday, January 5, 1971 21:30 │ date_time {1971, 1, 5, 21, 30, 3} │ {:F} │ Tuesday, January 5, 1971 21:30:03 │ date_time {1971, 1, 5, 21, 30, 3} │ {:g} │ 1/5/1971 21:30 │ date_time {1971, 1, 5, 21, 30, 3} │ {:G} │ 1/5/1971 21:30:03 │ date_time {1971, 1, 5, 21, 30, 3} │ {:m} │ January 5 ``` -------------------------------- ### Complete Console Application Example (C++ and CMake) Source: https://github.com/gammasoft71/xtd/blob/master/docs/writing_applicaion_console.md Presents the full, integrated code for a console application, including both the C++ source file and the CMakeLists.txt configuration file. This combines the setup and I/O functionalities. ```cpp #include using namespace xtd; class console1 { public: console1() { console::background_color(console_color::blue); console::foreground_color(console_color::white); console::write_line("What's your name ?"); auto name = console::read_line(); console::write_line("Hello, {}", name); } }; auto main() -> int { console1 {}; } ``` ```cmake cmake_minimum_required(VERSION 3.20) project(console1) find_package(xtd REQUIRED) add_sources(console1.cpp) target_type(CONSOLE_APPLICATION) ``` -------------------------------- ### Create Simple GUI Application with MessageBox in C++ using xtd Source: https://context7.com/gammasoft71/xtd/llms.txt Demonstrates creating a basic GUI application in C++ using xtd. It shows how to create a form with a button that, when clicked, displays a 'Hello, World!' message box. An alternative, simplified syntax using `form::create` and `button::create` is also presented. ```cpp #include class main_form : public form { public: main_form() { text("Hello world (message_box)"); button1.location({10, 10}); button1.parent(self_); button1.text("&Click me"); button1.click += delegate_ { message_box::show("Hello, World!"); }; } private: button button1; }; auto main() -> int { application::run(main_form {}); } // Alternative simplified syntax: auto main() -> int { auto main_form = form::create("Hello world (message_box)"); auto button1 = button::create(main_form, "&Click me", {10, 10}); button1.click += [] {message_box::show("Hello, World!");}; application::run(main_form); } ``` -------------------------------- ### Get Host Addresses with xtd::net::dns Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.core.examples/network/README.md Demonstrates how to retrieve IP addresses associated with a host name using the xtd::net::dns class. This function is useful for network diagnostics and establishing connections. ```c++ #include int main() { auto addresses = xtd::net::dns::get_host_addresses("www.example.com"); for (const auto& address : addresses) console::write_line(address.to_string()); } ``` -------------------------------- ### Hello World GUI Application in C++ Source: https://github.com/gammasoft71/xtd/blob/master/README.md This C++ code demonstrates a basic 'Hello World' program for a GUI application using the xtd library, similar to WinForms. It creates a simple form with a button that displays a message box when clicked. Dependencies include the xtd library. The input is user interaction (button click), and the output is a message box. ```cpp #include class main_form : public form { public: main_form() { text("Hello world (message_box)"); button1.location({10, 10}); button1.parent(self_); button1.text("&Click me"); button1.click += delegate_ { message_box::show("Hello, World!"); }; } private: button button1; }; auto main() -> int { application::run(main_form {}); } ``` ```cpp #include auto main() -> int { auto main_form = form::create("Hello world (message_box)"); auto button1 = button::create(main_form, "&Click me", {10, 10}); button1.click += [] {message_box::show("Hello, World!");}; application::run(main_form); } ``` -------------------------------- ### Get program exit code with xtd::environment::exit_code Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.core.examples/environment/README.md Shows how to retrieve the exit code of the application using xtd::environment::exit_code. This is useful for debugging or for other processes that might be monitoring the exit status of this application. ```cpp #include #include int main() { xtd::environment::exit_code(42); // Set an exit code std::cout << "Exit code: " << xtd::environment::exit_code() << std::endl; return 0; } ``` -------------------------------- ### Replace Startup Macro with Standard Main Function (C++) Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.forms.examples/tutorial/tutorial_console_write_line/README.md This C++ code shows an alternative to the `startup_` macro by defining a standard `main` function. This approach explicitly calls the application's `main` method and returns the environment's exit code, offering a more conventional entry point for the application. ```c++ int main(int argc, char* argv[]) { tutorial::simple::main(); return xtd::environment::exit_code(); } ``` -------------------------------- ### Get Host Entry with xtd::net::dns Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.core.examples/network/README.md Retrieves detailed information about a host, including its IP addresses and aliases, using the xtd::net::dns::get_host_entry method. This provides a comprehensive view of a network host. ```c++ #include int main() { auto host_entry = xtd::net::dns::get_host_entry("www.example.com"); console::write_line("Host name: {}", host_entry.host_name()); for (const auto& alias : host_entry.aliases()) console::write_line("Aliases: {}", alias); for (const auto& address : host_entry.address_list()) console::write_line("IP Address: {}", address.to_string()); } ``` -------------------------------- ### Hello World Console Application in C++ Source: https://github.com/gammasoft71/xtd/blob/master/README.md This C++ code demonstrates a basic 'Hello World' program for the console using the xtd library. It shows how to set console colors and print output. Dependencies include the xtd library. The primary input is the program logic, and the output is text printed to the console. ```cpp #include auto main() -> int { console::background_color(console_color::blue); console::foreground_color(console_color::white); console::write_line("Hello, World!"); } ``` ```cpp #include auto main() -> int { console::out << background_color(console_color::blue) << foreground_color(console_color::white) << "Hello, World!" << environment::new_line; } ``` -------------------------------- ### Get tick count with xtd::environment Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.core.examples/environment/README.md Demonstrates how to obtain the system's tick count (milliseconds since system startup) using xtd::environment::tick_count. This can be used for performance timing or measuring the duration of operations. ```cpp #include #include #include int main() { unsigned long long start_ticks = xtd::environment::tick_count(); std::this_thread::sleep_for(std::chrono::milliseconds(500)); unsigned long long end_ticks = xtd::environment::tick_count(); std::cout << "Elapsed time: " << (end_ticks - start_ticks) << " ms" << std::endl; return 0; } ``` -------------------------------- ### C++: startup_ with static void main() Source: https://github.com/gammasoft71/xtd/blob/master/docs/main_and_startup.md This snippet shows the usage of `startup_` with a static `main` member function that takes no arguments and returns void. It demonstrates iterating through command-line arguments and setting the exit code. ```cpp #include using namespace xtd; namespace examples { class program { public: static void main() { // Write arguments to the console output for (auto arg : environment::get_command_line_args()) console::write_line(arg); // return 42 environment::exit_code(42); } }; } startup_(examples::program::main); ``` -------------------------------- ### Get stack trace with xtd::diagnostics::stack_trace Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.core.examples/environment/README.md Shows how to generate and retrieve a stack trace using xtd::diagnostics::stack_trace. This is invaluable for debugging, as it provides a history of function calls leading up to the current point in the code. ```cpp #include #include void function_b() { xtd::diagnostics::stack_trace st; std::cout << "Stack trace inside function_b:\n" << st << std::endl; } void function_a() { function_b(); } int main() { function_a(); return 0; } ``` -------------------------------- ### Build and Run Example with CMake (CMake) Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.tunit.examples/others/tunit_config_main/README.md This CMakeLists.txt file configures the build process for the tunit_config_main example. It specifies the project name and includes the necessary xtd module. The `xtdc run` command is used to build and execute the project. ```cmake cmake_minimum_required(VERSION 3.20.0) project(tunit_config_main_example) find_package(xtd REQUIRED) add_executable(${PROJECT_NAME} src/tunit_config_main.cpp) target_link_libraries(${PROJECT_NAME} PRIVATE xtd::xtd) ``` -------------------------------- ### Create and Open a GUI Application with xtdc Source: https://github.com/gammasoft71/xtd/blob/master/docs/downloads.md This snippet demonstrates how to use the xtdc command-line tool to create a new GUI application named 'hello_world'. It then navigates into the newly created project directory and opens it, which will generate platform-specific project files (Visual Studio for Windows, Xcode for macOS, Code::Blocks for Linux). ```shell xtdc new gui hello_world cd hello_world xtdc open ``` -------------------------------- ### Manage current directory with xtd::environment Source: https://github.com/gammasoft71/xtd/blob/master/examples/xtd.core.examples/environment/README.md Demonstrates how to get and set the current working directory of an application using xtd::environment::current_directory. This functionality is useful for file operations or when an application needs to reference files relative to a specific directory. ```cpp #include #include int main() { std::cout << "Current directory: " << xtd::environment::current_directory() << std::endl; xtd::environment::current_directory("/tmp"); // Example: change directory std::cout << "New current directory: " << xtd::environment::current_directory() << std::endl; return 0; } ``` -------------------------------- ### Accessing command line arguments with xtd::environment in C++ Source: https://github.com/gammasoft71/xtd/blob/master/docs/main_and_startup.md Demonstrates how to retrieve the full command line and individual arguments using xtd::environment::command_line and xtd::environment::get_command_line_args. This allows access to command-line parameters even when the main function is declared without arguments. Requires the xtd library. ```cpp #include using namespace xtd; auto main() -> int { // Write the command line to the console output console::write_line(environment::command_line()); console::write_line(); // Write command line arguments to the console output for (auto arg : environment::get_command_line_args()) console::write_line(arg); } ``` -------------------------------- ### Demonstrate xtd::environment events Source: https://github.com/gammasoft71/xtd/blob/master/docs/doxygen/doxygen/xtd_core_examples.dox These examples focus on event handling within the xtd::environment class. They show how to manage program signals using cancel_signal and how to respond to program termination events with program_stopped. ```cpp #include #include #include void signal_handler(int signum) { std::cout << "Interrupt signal (" << signum << ") received.\n"; // Here you would typically perform cleanup operations xtd::environment::exit(signum); } int main() { // Register signal handler for SIGINT (Ctrl+C) signal(SIGINT, signal_handler); // Subscribe to the program_stopped event xtd::environment::program_stopped += [] (const xtd::environmentEventArgs& e) { std::cout << "Program is stopping with exit code: " << e.exit_code() << std::endl; }; std::cout << "Press Ctrl+C to send SIGINT signal...\n"; // Keep the program running to catch the signal while(true) { // do nothing } return 0; } ``` -------------------------------- ### Launch Process from Forms (C++) Source: https://github.com/gammasoft71/xtd/blob/master/docs/doxygen/doxygen/xtd_forms_examples.dox Demonstrates how to launch an external process from a form using the xtd library. This example is applicable to Windows, macOS, and Gnome environments. ```cpp /// Shows how to launch process from forms. /// @par Windows /// @image html process_form_w.png ///
/// @image html process_form_wd.png /// @par macOS /// @image html process_form_m.png ///
/// @image html process_form_md.png /// @par Gnome /// @image html process_form_g.png ///
/// @image html process_form_gd.png ``` -------------------------------- ### Enumerate Directories by Creation Time using directory_info::enumerate_directories (C++) Source: https://github.com/gammasoft71/xtd/blob/master/docs/common_io_tasks_enumerate_directories_and_files.md This example demonstrates listing directories created after a specific date using directory_info::enumerate_directories. It iterates through directories in a given path and filters them based on their creation time. ```cpp #include using namespace xtd; using namespace xtd::collections::generic; using namespace xtd::io; class program { public: static auto main() { // Set a variable to the Documents path. string doc_path = environment::get_folder_path(environment::special_folder::my_documents); directory_info dir_programs(doc_path); date_time start_of_2021(2021, 1, 1); list dirs; for (auto dir : dir_programs.enumerate_directories()) { if (dir.creation_time() >= start_of_2021) dirs.push_back(dir); }; for (auto di : dirs) { console::write_line("{}", di.name()); } } }; startup_(program::main); ``` -------------------------------- ### Using magic_enum with xtd for Enum Introspection in C++ Source: https://github.com/gammasoft71/xtd/blob/master/docs/enum_class.md Demonstrates how to leverage the magic_enum library with xtd to get the name, value, and all entries of an enum class. It includes examples of converting enum values to strings and integers, and listing all possible enum names and values. ```cpp #include #include using namespace magic_enum; using namespace xtd; enum class enum_test { value_one, value_two, value_three, value_four }; auto main() -> int { console::write_line("name = {}", enum_name(enum_test::value_four)); console::write_line("value = {}", enum_integer(enum_test::value_four)); console::write_line("as = {}", as(enum_test::value_four)); console::write_line("values = [{}] ", string::join(", ", enum_values())); console::write_line("names = {}", enum_names()); console::write("entries = ["); for (auto entry : enum_entries()) { static auto index = 0; console::write("{}({}, {})", index++ == 0 ? "" : ", ", as(entry.first), entry.second); } console::write_line("]"); } ``` -------------------------------- ### Create Test Fixture and Cases without Helpers in C++ Source: https://github.com/gammasoft71/xtd/blob/master/docs/writing_applicaion_test.md This example demonstrates creating a test fixture and test cases in C++ without using helper macros. Test components are registered explicitly using attributes, offering more control over the setup. This method requires manual registration of each test element. ```cpp #include using namespace xtd::tunit; namespace unit_tests { // Used test_class_attribute<> to register test fixture. class test; test_class_attribute test_class_attr {"test"}; // Create new test fixture inherited test_class. class test : public test_class { public: // Used class_initialize_attribute object to register class initialize method. class_initialize_attribute class_initialize_attr {"class_initialize", *this, &test::class_initialize}; // This method is called 1 time before test class run. static void class_initialize() { } // Used class_cleanup_attribute object to register class cleanup method. class_cleanup_attribute class_cleanup_attr {"class_cleanup", *this, &test::class_cleanup}; // This method is called 1 time after test class run. static void class_cleanup() { } // Used test_initialize_attribute object to register test initialize method. test_initialize_attribute test_initialize_attr {"test_initialize", *this, &test::test_initialize}; // This method is called before each test case of test fixture. static void test_initialize() { } // Used test_cleanup_attribute object to register test cleanup method. test_cleanup_attribute test_cleanup_attr {"test_cleanup", *this, &test::test_cleanup}; // This method that is called after each test case of test fixture. static void test_cleanup() { } // Used test_method_attribute object to register test case 1 method. test_method_attribute test_case1_attr {"test_case1", *this, &test::test_case1}; // Test case 1 void test_case1() { } // Used test_method_attribute object to register test case 2 method. test_method_attribute test_case2_attr {"test_case2", *this, &test::test_case2}; // Test case 2 void test_case2() { } // Used test_method_attribute object to register and ignore test case 3 method. test_method_attribute test_case3_attr {"test_case3", *this, &test::test_case3, test_state::ignored}; // Ignore Test case 3 void test_case3() { }; } auto main(int argc, char* argv[]) -> int { return console_unit_test(argv, argc).run(); } ``` -------------------------------- ### Adding Installation and Shortcut Scripts Source: https://github.com/gammasoft71/xtd/blob/master/scripts/CMakeLists.txt Includes batch and shell scripts for installing the project and creating shortcuts on different operating systems. These scripts streamline the installation process for end-users and developers. ```cmake add_sources( "install/install.cmd" "install/install.sh" "install/shortcut.cmd" "install/shortcut.sh" "install/xtd - Reference Guide.url" ) ```