{"id":4020,"date":"2022-01-03T05:14:52","date_gmt":"2022-01-03T05:14:52","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4020"},"modified":"2022-01-03T05:14:53","modified_gmt":"2022-01-03T05:14:53","slug":"7b-wxwidgets-wxfiledialog","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/03\/7b-wxwidgets-wxfiledialog\/","title":{"rendered":"7b.wxWidgets &#8211; wxFileDialog"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>In the sample code below, we use the wxFileDialog to select a text file , whose contents are then shown in a textbox.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dialog-file.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &amp;lt;wx\/wx.h&gt;\n#endif\n\n\nclass DialogFile: public wxFrame {\n\tpublic:\n\t\tDialogFile(const wxString&amp;amp; title);\n\t\tvoid OnClick(wxCommandEvent &amp;amp;event);\n\tprivate:\n\t\twxTextCtrl *mTxt;\n};\n\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">dialog-file.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;dialog-file.h&quot;\n\nDialogFile::DialogFile(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\twxButton *btn1 = new wxButton(panelMain, -1, wxT(&quot;Choose Text File&quot;));\n\tmTxt = new wxTextCtrl(panelMain, -1, wxT(&quot;&quot;), wxPoint(-1,-1), wxSize(-1,-1), wxTE_MULTILINE);\n\n\tvbox-&gt;Add(btn1, 0, wxALL | wxCENTER,5);\n\tvbox-&gt;Add(mTxt, 1, wxALL | wxEXPAND | wxCENTER, 5);\n\t\n\tbtn1-&gt;Bind(wxEVT_BUTTON, &amp;DialogFile::OnClick, this);\n\tCenter();\n}\n\n\t\nvoid DialogFile::OnClick(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\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.h\n<\/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\">\nmain.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-file.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tDialogFile *app = new DialogFile(wxT(&quot;File Open 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-10-41-28.png\" alt=\"\" class=\"wp-image-4024\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-41-28.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-41-28-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-10-41-44.png\" alt=\"\" class=\"wp-image-4025\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-41-44.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-41-44-300x240.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW In the sample code below, we use the wxFileDialog to select a text file , whose contents are then shown in a textbox. SAMPLE <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/03\/7b-wxwidgets-wxfiledialog\/\" title=\"7b.wxWidgets &#8211; wxFileDialog\">[&#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-4020","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\/4020","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=4020"}],"version-history":[{"count":4,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4020\/revisions"}],"predecessor-version":[{"id":4027,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4020\/revisions\/4027"}],"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=4020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}