Showing a message box in one line (π’ Beginner)
How to display a message box on a line in xtd unlike other frameworks.
wxWidgets codeβ
#include <wx/app.h>
#include <wx/msgdlg.h>
class Application : public wxApp {
bool OnInit() override {
wxMessageDialog {nullptr, "Hello, world!", "my_app"}.ShowModal();
return false;
}
};
wxIMPLEMENT_APP(Application);
- Requires an
Application
class inheritate fromwxApplication
- Override
OnInit
method - Creates
wxMessageDialog
and shows it withShowModal
method
Qt codeβ
#include <QApplication>
#include <QMessageBox>
auto main(int argc, char* argv[]) -> int {
auto application = QApplication {argc, argv};
QMessageBox {QMessageBox::Icon::NoIcon, "my_app", "Hello, World!"}.exec();
}
- Requires an instance of
QApplication
- Creates
QMessageBox
and shows it withexec
method
xtd codeβ
#include <xtd/xtd>
auto main() -> int {
// Just call message_box::show in one line!
message_box::show("Hello, World!", "my_app");
}
- Displays a message box with a single call to
message_box::show
Conclusionβ
- In xtd, showing a message box is exactly what it should be: one clear line of code. No ceremony. Just results.
- No boilerplate or unnecessary instantiation.
- You just have to focus on your own code.
- See xtd::forms::message_box for more information.
Did you know?
You donβt even need to create a main window or application in xtd to show a dialog. It's fully standalone.