{"id":4037,"date":"2022-01-03T05:58:49","date_gmt":"2022-01-03T05:58:49","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4037"},"modified":"2022-01-03T05:58:50","modified_gmt":"2022-01-03T05:58:50","slug":"7d-wxwidgets-creating-custom-dialog","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/03\/7d-wxwidgets-creating-custom-dialog\/","title":{"rendered":"7d.wxWidgets &#8211; Creating Custom Dialog"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>We now create a custom dialog which takes the code from the two previous sections and puts them together to show a dialog where you can load a text file in an editor and then change the font of the editor.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dialog-custom.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 DialogCustom: public wxFrame {\n\tpublic:\n\t\tDialogCustom(const wxString&amp; title);\n\t\tvoid OnFileClick(wxCommandEvent &amp;event);\n\t\tvoid OnFontClick(wxCommandEvent &amp;event);\n\tprivate:\n\t\twxTextCtrl *mTxt;\n};\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">dialog-custom.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/fontdlg.h&gt;\n#include &quot;dialog-custom.h&quot;\n\nDialogCustom::DialogCustom(const wxString&amp; title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,400)) {\n\n\twxPanel *panelMain = new wxPanel(this, -1);\n\twxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);\n\tpanelMain-&gt;SetSizer(vbox);\n\t\n\twxPanel *panelButtons = new wxPanel(panelMain,-1);\n\twxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);\n\tpanelButtons-&gt;SetSizer(hbox);\n\n\twxButton *btn1 = new wxButton(panelButtons, -1, wxT(&quot;Choose Text File&quot;));\n\twxButton *btn2 = new wxButton(panelButtons, -1, wxT(&quot;Choose Font&quot;));\n\thbox-&gt;Add(btn1, 1, wxALL | wxALIGN_LEFT, 5);\n\thbox-&gt;Add(btn2, 1, wxALL , 5);\n\n\tmTxt = new wxTextCtrl(panelMain, -1, wxT(&quot;&quot;), wxPoint(-1,-1), wxSize(-1,-1), wxTE_MULTILINE);\n\n\tvbox-&gt;Add(panelButtons, 0, wxALL ,5);\n\tvbox-&gt;Add(mTxt, 1, wxALL | wxEXPAND | wxCENTER, 5);\n\t\n\tbtn1-&gt;Bind(wxEVT_BUTTON, &amp;DialogCustom::OnFileClick, this);\n\tbtn2-&gt;Bind(wxEVT_BUTTON, &amp;DialogCustom::OnFontClick, this);\n\tCenter();\n}\n\n\t\nvoid DialogCustom::OnFileClick(wxCommandEvent &amp;event) {\n\twxFileDialog *dlg = new wxFileDialog(this, wxT(&quot;Open Text File&quot;), wxT(&quot;&quot;), wxT(&quot;&quot;), wxT(&quot;txt files (*.txt)|*.txt&quot;),\n\t\t\t\t\t\twxFD_OPEN | wxFD_FILE_MUST_EXIST);\n\tint retVal = dlg-&gt;ShowModal();\t\n\tif (retVal == wxID_OK) {\n   \t\twxString path = dlg-&gt;GetPath();\n\t\tmTxt-&gt;LoadFile(path);\n\t}\n}\n\n\t\nvoid DialogCustom::OnFontClick(wxCommandEvent &amp;event) {\n\n\twxFontDialog *dlg = new wxFontDialog(this);\n\tint retVal = dlg-&gt;ShowModal();\t\n\tif (retVal == wxID_OK) {\n\t\tmTxt-&gt;SetFont(dlg-&gt;GetFontData().GetChosenFont());\t\n\t}\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-custom.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tDialogCustom *app = new DialogCustom(wxT(&quot;Custom Dialog &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=\"400\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-11-26-48.png\" alt=\"\" class=\"wp-image-4039\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-11-26-48.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-11-26-48-300x240.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=\"500\" height=\"400\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-11-27-04.png\" alt=\"\" class=\"wp-image-4040\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-11-27-04.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-11-27-04-300x240.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=\"500\" height=\"400\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-11-27-24.png\" alt=\"\" class=\"wp-image-4041\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-11-27-24.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-11-27-24-300x240.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW We now create a custom dialog which takes the code from the two previous sections and puts them together to show a dialog where <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/03\/7d-wxwidgets-creating-custom-dialog\/\" title=\"7d.wxWidgets &#8211; Creating Custom Dialog\">[&#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-4037","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\/4037","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=4037"}],"version-history":[{"count":3,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4037\/revisions"}],"predecessor-version":[{"id":4043,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4037\/revisions\/4043"}],"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=4037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}