{"id":3946,"date":"2021-12-24T08:17:11","date_gmt":"2021-12-24T08:17:11","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=3946"},"modified":"2021-12-24T08:17:12","modified_gmt":"2021-12-24T08:17:12","slug":"6b-wxwidgets-using-connect","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2021\/12\/24\/6b-wxwidgets-using-connect\/","title":{"rendered":"6b. wxWidgets &#8211; Using Connect"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>We now take the sample from the previous section and implement the event handling using Connect instead of an Event table<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">events-connect.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 EventsConnect: public wxFrame {\n\tpublic:\n\t\tEventsConnect(const wxString&amp; title);\n\t\tvoid OnClick(wxCommandEvent &amp;event);\n\t\tvoid OnText(wxCommandEvent &amp;event);\n\n\tprivate:\n\t\twxStaticText *m_lbl;\t\n\t\twxTextCtrl *m_edit;\n};\n\nconst int ID_BTN_1 = 101;\nconst int ID_BTN_2 = 102;\nconst int ID_BTN_3 = 103;\nconst int ID_TXT_1 = 104;\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">events-connect.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;events-connect.h&quot;\n\nEventsConnect::EventsConnect(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\twxPanel *panelBase = new wxPanel(panelMain, -1);\n\twxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);\n\n\tpanelBase-&gt;SetSizer(hbox);\n\n\twxButton *btn1 = new wxButton(panelBase, ID_BTN_1, wxT(&quot;Button 1&quot;));\n\twxButton *btn2 = new wxButton(panelBase, ID_BTN_2, wxT(&quot;Button 2&quot;));\n\twxButton *btn3 = new wxButton(panelBase, ID_BTN_3, wxT(&quot;Button 3&quot;));\n\n\tm_edit = new wxTextCtrl(panelBase, ID_TXT_1, wxT(&quot;&quot;));\n\n\thbox-&gt;Add(btn1, 1, wxALL,5);\n\thbox-&gt;Add(btn2, 1, wxALL,5);\n\thbox-&gt;Add(btn3, 1, wxALL,5);\n\thbox-&gt;Add(m_edit, 2, wxALL,5);\n\n\tvbox-&gt;Add(panelBase,1, wxALL,2);\n\n\tm_lbl = new wxStaticText(panelMain, -1, wxT(&quot;show event handling here&quot;));\n\tvbox-&gt;Add(m_lbl, 1, wxALL | wxALIGN_CENTER);\n\t\n\tConnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(EventsConnect::OnClick));\n\tConnect(wxEVT_TEXT, wxCommandEventHandler(EventsConnect::OnText));\n\tCenter();\n}\n\n\t\nvoid EventsConnect::OnClick(wxCommandEvent &amp;event) {\n\t\n\twxString strId = wxString::Format(wxT(&quot;%d&quot;), event.GetId());\n\tstrId.Append(wxString(&quot; clicked&quot;));\n\tm_lbl-&gt;SetLabel(strId);\n}\n\nvoid EventsConnect::OnText(wxCommandEvent &amp;event) {\n\t  m_lbl-&gt;SetLabel(m_edit-&gt;GetValue());\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;events-connect.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tEventsConnect *app = new EventsConnect(wxT(&quot;Events Connect&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\/2021\/12\/Screenshot-from-2021-12-24-13-46-24.png\" alt=\"\" class=\"wp-image-3949\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-24-13-46-24.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-24-13-46-24-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=\"500\" height=\"200\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-24-13-46-08.png\" alt=\"\" class=\"wp-image-3950\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-24-13-46-08.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-24-13-46-08-300x120.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW We now take the sample from the previous section and implement the event handling using Connect instead of an Event table SAMPLE CODE events-connect.h <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2021\/12\/24\/6b-wxwidgets-using-connect\/\" title=\"6b. wxWidgets &#8211; Using Connect\">[&#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],"tags":[],"class_list":["post-3946","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cc"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3946","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=3946"}],"version-history":[{"count":3,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3946\/revisions"}],"predecessor-version":[{"id":3951,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3946\/revisions\/3951"}],"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=3946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=3946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=3946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}