xtd 0.2.0
console_window_size.cpp

Shows how to use xtd::console::set_window_size method.

#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto orig_width = 0, width = 0;
auto orig_height = 0, height = 0;
auto m1 = "The current window width is {0}, and the current window height is {1}.";
auto m2 = "The new window width is {0}, and the new window height is {1}.";
auto m4 = " (Press any key to continue...)";
//
// Step 1: Get the current window dimensions.
//
orig_width = console::window_width();
orig_height = console::window_height();
//
// Step 2: Cut the window to 1/4 its original size.
//
width = orig_width / 2;
height = orig_height / 2;
console::set_window_size(width, height);
//
// Step 3: Restore the window to its original size.
//
console::set_window_size(orig_width, orig_height);
// This code produces the following output :
//
// The current window width is 100, and the current window height is 60.
// (Press any key to continue...)
// The new window width is 50, and the new window height is 30.
// (Press any key to continue...)
// The current window width is 100, and the current window height is 60.
static int32 window_height()
Gets the height of the console window area.
static void set_window_size(int32 width, int32 height)
Sets the height and width of the console window to the specified values.
static console_key_info read_key()
Obtains the next character or function key pressed by the user. The pressed key is displayed in the c...
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static int32 window_width()
Gets the width of the console window area.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8