{"id":3788,"date":"2021-12-13T05:25:49","date_gmt":"2021-12-13T05:25:49","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=3788"},"modified":"2021-12-13T05:25:50","modified_gmt":"2021-12-13T05:25:50","slug":"3b-wxwidgets-application-icon","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2021\/12\/13\/3b-wxwidgets-application-icon\/","title":{"rendered":"3b. wxWidgets -Application Icon"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>Adding an application icon is fairly simple. However the behaviour may differ based on the underlying OS. The standard behaviour of an application icon is that it shows in the titlebar of the main application window as well as the application window in the OS taskbar. In some cases, the icon may appear in the titlebar but not in the taskbar or vice versa. <\/p>\n\n\n\n<p>The default format which wxWidgets uses for icons is the xpm format, which is quite uncommon. However standard ico files can be also be used. As long as the icon size is square eg.16&#215;16 , 32&#215;32 etc. they should work.<\/p>\n\n\n\n<p>If your application uses as lot of static resources like fonts, images etc, then the application icon would come from a resource file. But at this time, we are keeping it simple and it takes one line of code to show an application icon.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">appicon.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 AppIcon: public wxFrame {\n\n\tpublic:\n\t\tAppIcon(const wxString&amp; title);\n};\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">appicon.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;appicon.h&quot;\n\nAppIcon::AppIcon(const wxString&amp; title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,200)) {\n\n\tSetIcon(wxIcon(wxT(&quot;app.xpm&quot;)));\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;appicon.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tAppIcon *app = new AppIcon(wxT(&quot;Application Icon&quot;));\n\tapp-&gt;Show(true);\n\n}\n\n<\/pre><\/div>\n\n\n<p>The output is shown below. In this case, Ubuntu 18.0 does not show the icon in the titlebar, but only in the task bar.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"600\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-13-10-51-08.png\" alt=\"\" class=\"wp-image-3793\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-13-10-51-08.png 666w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-13-10-51-08-620x559.png 620w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-13-10-51-08-300x270.png 300w\" sizes=\"auto, (max-width: 666px) 100vw, 666px\" \/><\/figure>\n\n\n\n<p>The code uses the sample xpm file. You can change it to use the ico file to see how it looks. The ico file is given below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/app.ico\" alt=\"\" class=\"wp-image-3794\"\/><figcaption>app.ico<\/figcaption><\/figure>\n\n\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW Adding an application icon is fairly simple. However the behaviour may differ based on the underlying OS. The standard behaviour of an application icon <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2021\/12\/13\/3b-wxwidgets-application-icon\/\" title=\"3b. wxWidgets -Application Icon\">[&#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-3788","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\/3788","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=3788"}],"version-history":[{"count":6,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3788\/revisions"}],"predecessor-version":[{"id":3796,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3788\/revisions\/3796"}],"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=3788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=3788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=3788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}