{"id":4010,"date":"2022-01-03T04:37:38","date_gmt":"2022-01-03T04:37:38","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4010"},"modified":"2022-01-03T04:38:20","modified_gmt":"2022-01-03T04:38:20","slug":"7b-wxwidgets-wxmessagedialog","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/03\/7b-wxwidgets-wxmessagedialog\/","title":{"rendered":"7a.wxWidgets &#8211; wxMessageDialog"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>In the sample code below, we will invoke 4 different kinds of system dialogs when a button is clicked.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dialog-messages.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n\n\nclass DialogMessages: public wxFrame {\n\tpublic:\n\t\tDialogMessages(const wxString&amp; title);\n\t\tvoid OnClick(wxCommandEvent &amp;event);\n\n};\n\nconst int ID_BTN_1 = 101;\nconst int ID_BTN_2 = 102;\nconst int ID_BTN_3 = 103;\nconst int ID_BTN_4 = 104;\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">dialog-messages.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;dialog-messages.h&quot;\n\nDialogMessages::DialogMessages(const wxString&amp; title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,200)) {\n\n\twxPanel *panelMain = new wxPanel(this, -1);\n\twxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);\n\tpanelMain-&gt;SetSizer(vbox);\n\t\n\twxButton *btn1 = new wxButton(panelMain, ID_BTN_1, wxT(&quot;Info&quot;));\n\twxButton *btn2 = new wxButton(panelMain, ID_BTN_2, wxT(&quot;Error&quot;));\n\twxButton *btn3 = new wxButton(panelMain, ID_BTN_3, wxT(&quot;Question&quot;));\n\twxButton *btn4 = new wxButton(panelMain, ID_BTN_4, wxT(&quot;Exclamation&quot;));\n\n\tvbox-&gt;Add(btn1, 1, wxALL | wxEXPAND | wxCENTER,5);\n\tvbox-&gt;Add(btn2, 1, wxALL | wxEXPAND | wxCENTER,5);\n\tvbox-&gt;Add(btn3, 1, wxALL | wxEXPAND | wxCENTER,5);\n\tvbox-&gt;Add(btn4, 1, wxALL | wxEXPAND | wxCENTER,5);\n\n\tbtn1-&gt;Bind(wxEVT_BUTTON, &amp;DialogMessages::OnClick, this);\n\tbtn2-&gt;Bind(wxEVT_BUTTON, &amp;DialogMessages::OnClick, this);\n\tbtn3-&gt;Bind(wxEVT_BUTTON, &amp;DialogMessages::OnClick, this);\n\tbtn4-&gt;Bind(wxEVT_BUTTON, &amp;DialogMessages::OnClick, this);\n\tCenter();\n}\n\n\t\nvoid DialogMessages::OnClick(wxCommandEvent &amp;event) {\n\t\n\tint id = event.GetId();\n\twxString msg = wxT(&quot;&quot;);\n\twxString title = wxT(&quot;&quot;);\n\tint flags = wxOK;\n\t\n\tswitch (id) {\n\t\tcase ID_BTN_1:\n\t\t\ttitle = &quot;Info&quot;;\n\t\t\tmsg = &quot;This is an informational message&quot;;\n\t\t\tbreak;\n\t\tcase ID_BTN_2:\n\t\t\ttitle = &quot;Error&quot;;\n\t\t\tmsg = &quot;This is an error message&quot;;\n\t\t\tflags |= wxICON_ERROR;\n\t\t\tbreak;\n\n\t\tcase ID_BTN_3:\n\t\t\ttitle = &quot;Question&quot;;\n\t\t\tmsg = &quot;This is a question&quot;;\n\t\t\tflags |= wxICON_QUESTION;\n\t\t\tbreak;\n\n\t\tcase ID_BTN_4:\n\t\t\ttitle = &quot;Exclamation&quot;;\n\t\t\tmsg = &quot;This is a message with exclamation&quot;;\n\t\t\tflags |= wxICON_EXCLAMATION;\n\t\t\tbreak;\n\t}\n\n\twxMessageDialog *dlg = new wxMessageDialog(NULL, msg, title, flags);\n\tdlg-&gt;ShowModal();\n}\n\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n\nclass Main: public wxApp {\n\n\tpublic:\n\t\tvirtual bool OnInit();\n};\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;main.h&quot;\n#include &quot;dialog-messages.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tDialogMessages *app = new DialogMessages(wxT(&quot;Dialog Messages&quot;));\n\tapp-&gt;Show(true);\n\n}\n\n<\/pre><\/div>\n\n\n<p>The output is shown below<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"200\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-04-32.png\" alt=\"\" class=\"wp-image-4013\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-04-32.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-04-32-300x120.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"390\" height=\"152\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-04-46.png\" alt=\"\" class=\"wp-image-4014\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-04-46.png 390w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-04-46-300x117.png 300w\" sizes=\"auto, (max-width: 390px) 100vw, 390px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"332\" height=\"152\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-04-59.png\" alt=\"\" class=\"wp-image-4015\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-04-59.png 332w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-04-59-300x137.png 300w\" sizes=\"auto, (max-width: 332px) 100vw, 332px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"286\" height=\"152\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-05-14.png\" alt=\"\" class=\"wp-image-4016\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"404\" height=\"152\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-05-28.png\" alt=\"\" class=\"wp-image-4017\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-05-28.png 404w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-05-28-300x113.png 300w\" sizes=\"auto, (max-width: 404px) 100vw, 404px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW In the sample code below, we will invoke 4 different kinds of system dialogs when a button is clicked. SAMPLE CODE dialog-messages.h dialog-messages.cpp main.h <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/03\/7b-wxwidgets-wxmessagedialog\/\" title=\"7a.wxWidgets &#8211; wxMessageDialog\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,365],"tags":[],"class_list":["post-4010","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cc","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4010","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=4010"}],"version-history":[{"count":4,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4010\/revisions"}],"predecessor-version":[{"id":4019,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4010\/revisions\/4019"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/3595"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=4010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}