![digitalparticles | Embarcadero RAD Studio Delphi C++Builder Blogs digital particles](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/04/digital-particles-4558191-1489759.jpg?resize=1140%2C500&ssl=1)
- Use Modern GUI Forms
Modern C++ compilers with IDE (Visual C++, C++ Builder, Objective-C, Android Studio, etc.) use a graphical interface by operating system behaviors of the application compiled. Console-based applications are good, but in some cases, you may need to add more features. UI elements make it easy to use applications and understand things on the user side.
Also, these UI elements, graphics, and images make your application visually stunning.
Visual C++ has third-party applications that support skins/styles for UI elements like SkinFramework and SkinCrafter for previous Visual C++ versions.
Skin Framework for Visual C++ MFC provides a skinning user interface framework that was developed with Windows Themes (Visual Styles) in mind. Themed applications can be created with only a few lines of code.
![15 Tips tourfirst | Embarcadero RAD Studio Delphi C++Builder Blogs 15 tips tour first](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/04/15-Tips-tour_first-8029422.gif?resize=300%2C289&ssl=1)
SkinCrafter is another choice for older Visual C++ applications (2012 or earlier). Application skinning is available for a large range of programming languages, tools, and frameworks in SkinCrafter. Apparently, it has no support for the latest Visual C++ versions.
![222 | Embarcadero RAD Studio Delphi C++Builder Blogs 222](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/04/222-8707842.png?resize=300%2C119&ssl=1)
RAD Studio and C++ Builder offer a great variety of styles on both VCL and FMX applications. They also allow users to change the style of application on runtime. These styles can be used for multiplatform applications and can be customized by using the included Bitmap Style Designer in RAD Studio. You can also create a new style from scratch. The easiest way to get started with a brand new style is to use the VCL style template in the Bitmap Style Designer as a guide. VCL Styles supports the Windows theme engine and FMX styles for the cross-platform FireMonkey UI framework are compatible with other operating systems. In addition to window and UI element skins, Styles also comes with a lot of modern icons. Most VCL and FMX Styles are free, and new free versions also can be downloaded by GetIt or by other online web pages.
![333 | Embarcadero RAD Studio Delphi C++Builder Blogs 333](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/04/333-2438160.png?resize=300%2C191&ssl=1)
Table of Contents
Tip 6: Develop GUI-based applications to make easy, understandable apps with stunning graphics.
- Use UI element properties as an output or use UI element methods
In C++, you often write to the console via std::cout, an object is used with streams and so supports the << operator; the direction of arrows shows the output, and anything on the right side of this operator goes as an output. For example:
1 2 3 4 5 6 7 |
include <iostream> int main() { std::cout << "This is in chars"; return 0 } |
In Modern C++, do not use cout. In backend applications or other OS applications use std::wcout as in the example below. Like strings, this is because it’s a wide character output, ie Unicode.
1 2 3 4 5 6 7 |
include <iostream> int main() { std::wcout << L"This is in wide chars"; return 0 } |
In general, everything goes on Unicode strings or wide strings in Modern C++, and UI apps never use std::cout or std::wcout. Because modern applications are supported with GUIs like buttons, edit boxes, text boxes, drop-down combo boxes, menus, and so on and Modern C++ development IDEs (like C++ Builder, Visual C++) also support Unicode strings, we use the properties of any components as an output instead of using cout.
For example, we can output the name and age to a text property of a label in C++ Builder as below.
1 2 3 4 5 |
String name = L"John"; int age = 25; Label1->Text = name; Label2->Text = IntToStr(age); |
This print() function example below in C++ Builder outputs Unicode string to Lines of a Memo component.
1 2 3 4 5 |
void print(String txt) { Form1->Memo1->Lines->Add(txt); return 0; } |
Tip 7: Use UI element properties as an output or UI element methods to output your data.
8. Use UI element properties as an input or use UI element methods
In a console application, the std::cin object is used with the >> operator; the direction of the arrows shows the input, and anything on the right side of this operator goes as an output. For example:
1 2 3 4 5 6 7 8 9 10 11 |
#include <iostream> int main() { std::string name; std::cout << "Name please:"; std::cin >> name; return 0; } |
As we described before, Unicode strings or wide strings are needed. In Modern C++, do not use std::cin in backend applications or other OS applications; try to use std::wcin as in the example below.
1 2 3 4 5 6 7 8 9 10 11 |
#include <iostream> int main() { std::wstring name; std::wcout << L"Name please:"; std::wcin >> name; return 0; } |
As described above, in visual programming we add texts, text boxes, buttons, labels, drop down labels, and so on, and we call them UI elements, components, or visual tools.
In Modern C++ we use these element properties as an input, or we use their methods to get inputs. For example, we can get input for the name and age from the text property of an edit (text input) component in C++ Builder as below.
1 2 |
String name = Edit1->Text; int age = StrToInt(Edit2->Text) |
Tip 8: Use UI element properties as an input or use UI element methods to get input.
- Use methods and features of standard libraries
Many libraries in C++ provide functions for many different applications, while some basic libraries that are like a standard for all c++ applications: STL (Standard Template Library, part of all C++ distributions), which has different implementations depending on the vendor, eg the GNU C++ Standard Library (libstdc++), Microsoft C++ Standard Library (STL), and LLVM C++ Standard Library (libc++).
The STL defines its methods, types etc in the std:: namespace. You can read about the features included in the STL here. There is a great video that shows most of the algorithms of STL here.
Algorithms in this library are optimized well to run faster, and are compatible with many data types. For example, instead of writing a sorting method for a function (e.g., bubble sort, quick sort, merge sort, etc.), you can use parallel algorithms to do multitask operations to use all CPU cores. Some other examples are heaps, permutation, numerical algorithms, querying, searching, fill, copy, move, remove, unique operations in memory, and transform algorithms.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include #include #include int main() { std::vector vec{ 36, 11, 9, 5, 15, 45, 5, 3 , 98, 23, 65}; for (auto i: vec) std::cout << i << ','; std::cout << 'n'; std::sort(std::execution::par, vec.begin(), vec.end()); for (auto i: vec) std::cout << i << ','; std::cout << 'n'; getchar(); return 0; } |
Boost Library is another great library to use more algorithms. Boost provides free and well-reviewed portable C++ source libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful and usable across a broad spectrum of applications. The Boost license encourages both commercial and noncommercial use.
Tip 9: Use optimized methods and features of standard libraries as much as possible.
Read part 1 of this blog post here
Read part 3 of this blog post here
Find valuable insights on how you can perform a C++ std conversion in this article.
Additionally, learn about TURLStream and how it extends the base class constructor C++.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition