xtd 0.2.0
process_form.cpp

Shows how to launch process from forms.

Windows

macOS

Gnome

#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/button_images>
#include <xtd/forms/form>
#include <xtd/forms/vertical_layout_panel>
#include <xtd/diagnostics/process>
#include <xtd/invalid_operation_exception>
using namespace xtd;
using namespace xtd::diagnostics;
using namespace xtd::io;
using namespace xtd::forms;
class main_form : public form {
public:
main_form() {
text("Process form example");
controls().push_back(layout_panel);
client_size({350, 540});
layout_panel.controls().push_back_range({xtd_web_button, write_mail_button, open_home_folder_button, open_readme_txt_file_button, open_gammasoft_png_file_button, open_calculator_button});
layout_panel.dock(dock_style::fill);
layout_panel.control_layout_style(xtd_web_button, {size_type::auto_size, true});
layout_panel.control_layout_style(write_mail_button, {size_type::auto_size, true});
layout_panel.control_layout_style(open_home_folder_button, {size_type::auto_size, true});
layout_panel.control_layout_style(open_readme_txt_file_button, {size_type::auto_size, true});
layout_panel.control_layout_style(open_gammasoft_png_file_button, {size_type::auto_size, true});
layout_panel.control_layout_style(open_calculator_button, {size_type::auto_size, true});
xtd_web_button.image(button_images::from_name("text-html", drawing::size(64, 64)));
xtd_web_button.image_align(content_alignment::middle_left);
xtd_web_button.text("Open xtd website...");
xtd_web_button.click += [] {
process::start("https://gammasoft71.github.io/xtd");
};
write_mail_button.image(button_images::from_name("document-send", drawing::size(64, 64)));
write_mail_button.image_align(content_alignment::middle_left);
write_mail_button.text("Write mail...");
write_mail_button.click += [] {
process::start("mailto:gammasoft71@gmail.com?subject=Hi%20Gammasoft71&body=xtd%20is%20a%20great%20project.%0D%0A%20");
};
open_home_folder_button.image(button_images::from_name("folder-home", drawing::size(64, 64)));
open_home_folder_button.image_align(content_alignment::middle_left);
open_home_folder_button.text("Open home folder...");
open_home_folder_button.click += [] {
};
open_readme_txt_file_button.image(button_images::from_name("text-x-generic", drawing::size(64, 64)));
open_readme_txt_file_button.image_align(content_alignment::middle_left);
open_readme_txt_file_button.text("Open \"readme.txt\" file...");
open_readme_txt_file_button.click += [] {
file::write_all_text(path::combine(path::get_temp_path(), "readme.txt"), "Tests open file \"readme.txt\" with xtd::diagnostics::process class.\n");
};
open_gammasoft_png_file_button.image(button_images::from_name("image-x-generic", drawing::size(64, 64)));
open_gammasoft_png_file_button.image_align(content_alignment::middle_left);
open_gammasoft_png_file_button.text("Open \"gammasoft.png\" file...");
open_gammasoft_png_file_button.click += [] {
images::from_name("gammasoft", drawing::size(512, 512)).save(path::combine(path::get_temp_path(), "gammasoft.png"));
};
open_calculator_button.image(button_images::from_name("accessories-calculator", drawing::size(64, 64)));
open_calculator_button.image_align(content_alignment::middle_left);
open_calculator_button.text("Launch Calculator...");
open_calculator_button.click += [] {
else if (environment::os_version().is_macos()) process::start(process_start_info {"Calculator"});
else if (environment::os_version().is_linux()) process::start(process_start_info {"gnome-calculator"}.use_shell_execute(false));
else throw invalid_operation_exception("Calculator application unknown.");
};
}
private:
vertical_layout_panel layout_panel;
button xtd_web_button;
button write_mail_button;
button open_home_folder_button;
button open_readme_txt_file_button;
button open_gammasoft_png_file_button;
button open_calculator_button;
};
auto main() -> int {
}
Specifies a set of values that are used when you start a process.
Definition process_start_info.hpp:39
const xtd::string & working_directory() const noexcept
When the xtd::diagnostics::process_start_info::use_shell_execute property is false,...
bool use_shell_execute() const noexcept
Gets a value indicating whether to use the operating system shell to start the process.
bool start()
Starts (or reuses) the process resource that is specified by the xtd::diagnostics::process::start_inf...
@ home
The file system directory that contains home folder.
Definition environment.hpp:243
static xtd::string get_folder_path(environment::special_folder folder)
Gets the path to the system special folder that is identified by the specified enumeration.
Definition environment.hpp:613
static xtd::operating_system os_version() noexcept
Gets an xtd::operating_system object that contains the current platform identifier and version number...
static void run()
Begins running a standard application message loop on the current thread, without a form.
static xtd::drawing::image from_name(const xtd::string &name)
Gets image object with specified name.
Definition button_images.hpp:193
Represents a Windows button control.
Definition button.hpp:49
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
static xtd::drawing::image from_name(const xtd::string &name)
Gets image object with specified name.
Definition images.hpp:1268
Used to group collections of vertically aligned controls.
Definition vertical_layout_panel.hpp:32
The exception that is thrown when the format of an argument does not meet the parameter specification...
Definition invalid_operation_exception.hpp:19
static void write_all_text(const xtd::string &path, type_t text)
Writes text to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:359
static xtd::string get_temp_path() noexcept
Returns the path of the current user's temporary folder.
static xtd::string combine(const xtd::string &path1, const xtd::string &path2)
Combines two path strings.
@ fill
All the control's edges are docked to the all edges of its containing control and sized appropriately...
Definition dock_style.hpp:35
@ auto_size
The control should be automatically sized to share space with its peers.
Definition size_type.hpp:24
@ middle_left
Content is vertically aligned in the middle, and horizontally aligned on the left.
Definition content_alignment.hpp:29
The xtd::diagnostics namespace provides classes that allow you to interact with system processes,...
Definition assert_dialog_result.hpp:10
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.hpp:17
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Stores an ordered pair of integers, which specify a height and width.
Definition size.hpp:31