{"id":4391,"date":"2022-07-28T03:14:52","date_gmt":"2022-07-28T03:14:52","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4391"},"modified":"2022-07-28T03:14:52","modified_gmt":"2022-07-28T03:14:52","slug":"setting-up-wxwidgets-environment-for-visual-studio","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/07\/28\/setting-up-wxwidgets-environment-for-visual-studio\/","title":{"rendered":"Setting up wxWidgets Environment for Visual Studio"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>In another blog post, <a rel=\"noopener\" href=\"https:\/\/truelogic.org\/wordpress\/2021\/12\/06\/setting-up-wxwidgets-environment-for-c-in-windows-10\/\" target=\"_blank\">we saw Setting up wxWidgets Environment for C++ in Windows 10<\/a>  without having to use Visual Studio. The main problem with that method is that we have to take care of everything ourselves, specially the handling of make files. With that in mind, this blog post explains how to leverage Visual Studio to do wxWidgets development. Using an IDE not only makes things easier but faster as well.<\/p>\n\n\n\n<p>This has been tested with Visual Studio 2022. There seem to be some issues if you try this with VS 2019 or older. <\/p>\n\n\n\n<p><strong>INSTALL VCPKG<\/strong><\/p>\n\n\n\n<p>What we need is a package called vcpkg which is an open source tool developed by Microsoft to help incorporate third-party C++ libraries and frameworks for use in VS. To do that. make sure you have Git installed in your system. Go to the Github repo for vcpkg. <a href=\"https:\/\/github.com\/microsoft\/vcpkg\">https:\/\/github.com\/microsoft\/vcpkg<\/a><\/p>\n\n\n\n<p>In the command line, go to the directory of your choice eg. <em>d:\\projects<\/em> and type in<em> git clone https:\/\/github.com\/microsoft\/vcpkg.git<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">D:\\projects&gt;git clone https:\/\/github.com\/microsoft\/vcpkg.git\nCloning into 'vcpkg'...\nremote: Enumerating objects: 158493, done.\nremote: Counting objects: 100% (477\/477), done.\nremote: Compressing objects: 100% (257\/257), done.\nremote: Total 158493 (delta 275), reused 353 (delta 220), pack-reused 158016R\nReceiving objects: 100% (158493\/158493), 61.41 MiB | 3.80 MiB\/s, done.\nResolving deltas: 100% (100285\/100285), done.\nChecking out files: 100% (9007\/9007), done.\n<\/pre>\n\n\n\n<p>Now change the directory to vcpkg eg. <em>cd vcpkg<\/em> and run the following command:<\/p>\n\n\n\n<p><em>bootstrap-vcpkg.bat<\/em><\/p>\n\n\n\n<p>Now we are going to use vcpkg to setup wxWidgets for 64 bit Windows. To do that run<\/p>\n\n\n\n<p><em>vcpkg install wxWidgets:x64-windows<\/em><\/p>\n\n\n\n<p>This will take a while to install and setup.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"488\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/07\/vcpkg-940x488.png\" alt=\"\" class=\"wp-image-4396\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/07\/vcpkg-940x488.png 940w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/07\/vcpkg-620x322.png 620w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/07\/vcpkg-300x156.png 300w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/07\/vcpkg-768x399.png 768w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/07\/vcpkg.png 984w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p>Next we integrate wxWidgets libraries to work with Visual Studio via vcpkg. Use the following command:<\/p>\n\n\n\n<p><em>vcpkg integrate install<\/em><\/p>\n\n\n\n<p>The last step is to install the wxWidgets library now. Use the command<\/p>\n\n\n\n<p><em>vcpkg install wxwidgets:x64-windows<\/em><\/p>\n\n\n\n<p>Now we are ready to test out a wxWidgets program in Visual Studio<\/p>\n\n\n\n<p><strong>BUILD SAMPLE WXWIDGETS APPLICATION<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Open Visual Studio. Choose a new Project Type as C++ Empty Windows Project (C++, Windows, Console)<\/li><li>Lets call the project as FourthProject. You can choose whatever name you like .<\/li><li>Under Header Files, create a new file FourthProject.h and put the following code:<\/li><\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#pragma once\nclass MyProjectApp : public wxApp\n{\npublic:\n    MyProjectApp();\n    virtual ~MyProjectApp();\n    virtual bool OnInit() override;\n};\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\"><li>Under Source Files, create a new file FourthProject.cpp and put the following code:<\/li><\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wx.h&gt;\n#include &quot;FourthProject.h&quot;\n\nMyProjectApp::MyProjectApp()\n{\n}\n\nMyProjectApp::~MyProjectApp()\n{\n}\n\nbool MyProjectApp::OnInit()\n{\n\twxFrame* mainFrame = new wxFrame(nullptr, wxID_ANY, L&quot;MyProject&quot;);\n\tmainFrame-&gt;Show(true);\n\treturn true;\n}\n\nwxIMPLEMENT_APP(MyProjectApp);\nwxIMPLEMENT_WXWIN_MAIN_CONSOLE;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\"><li>Build the Solution. If all goes well, the project will be built without errors.<\/li><li>Run the project, and you should see the following output.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"389\" height=\"250\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/07\/window.png\" alt=\"\" class=\"wp-image-4401\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/07\/window.png 389w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/07\/window-300x193.png 300w\" sizes=\"auto, (max-width: 389px) 100vw, 389px\" \/><\/figure>\n\n\n\n<p>The only small issue here is that since we have created a Windows Console project, it runs a terminal window first before running the actual application. We have to change the project type from Console to Windows. For that the following steps are required:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>In the Solution Explorer, right click the Project item and select Properties<\/li><li>In the Properties dialog, go to Linker-&gt;System<\/li><li>In the Subsystem field, change the value to \/SUBSYSTEM:WINDOWS and click Ok<\/li><\/ul>\n\n\n\n<p>Rebuild the project and now the application will run without the background console window.<\/p>\n\n\n\n<p>If you deploy the application on some other computer, then make sure all the dll files in the execution folder are also copied along with the main exe.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW In another blog post, we saw Setting up wxWidgets Environment for C++ in Windows 10 without having to use Visual Studio. The main problem <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/07\/28\/setting-up-wxwidgets-environment-for-visual-studio\/\" title=\"Setting up wxWidgets Environment for Visual Studio\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":4405,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[365],"tags":[],"class_list":["post-4391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4391","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=4391"}],"version-history":[{"count":13,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4391\/revisions"}],"predecessor-version":[{"id":4407,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4391\/revisions\/4407"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/4405"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=4391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}