#include#include #include #include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget *window = new QWidget; window->setWindowTitle("Calculator"); QGridLayout *layout = new QGridLayout; QLineEdit *display = new QLineEdit; display->setReadOnly(true); display->setText("0"); layout->addWidget(display, 0, 0, 1, 4); const char *buttons[16] = {"7", "8", "9", "/", "4", "5", "6", "*", "1", "2", "3", "-", "0", "C", "=", "+"}; QPushButton *button[16]; for (int i = 0; i < 16; i++) { button[i] = new QPushButton(buttons[i]); layout->addWidget(button[i], i/4+1, i%4); } window->setLayout(layout); window->show(); return app.exec(); }
#includeint main(int argc, char *argv[]) { auto app = Gtk::Application::create(argc, argv); Gtk::MessageDialog dialog("Hello, world!", false, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK); dialog.set_title("Message"); dialog.set_modal(true); dialog.run(); return 0; }
#includeIn this example, we create a MyFrame class that inherits from wxFrame. We create a wxPanel and a wxButton inside the frame and bind an event handler to the button click event. We also create a MyApp class that inherits from wxApp and define its OnInit method to create and show the frame. Finally, we use the wxIMPLEMENT_APP macro to initialize the application with MyApp. When the button is clicked, we show a message box with a message.class MyFrame : public wxFrame { public: MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150)) { wxPanel *panel = new wxPanel(this); wxButton *button = new wxButton(panel, wxID_ANY, "Click me!", wxPoint(30, 30)); button->Bind(wxEVT_BUTTON, &MyFrame::OnButtonClicked, this); } private: void OnButtonClicked(wxCommandEvent& event) { wxMessageBox("Hello, world!", "Message", wxOK | wxICON_INFORMATION, this); } wxDECLARE_EVENT_TABLE(); }; wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_BUTTON(wxID_ANY, MyFrame::OnButtonClicked) wxEND_EVENT_TABLE() class MyApp : public wxApp { public: virtual bool OnInit() { MyFrame *frame = new MyFrame("Hello world"); frame->Show(true); return true; } }; wxIMPLEMENT_APP(MyApp);