This procedure creates a minimal wxWidgets static-library app that does nothing useful, but provides a framework for building more complex apps. Here is what it looks like, in all its glory:

Versions Used:

  • Microsoft Visual Studio Community 2022, Version 17.4.1
  • wxWidgets 3.2.2.1

Main Reference:

Other References:

This procedure follows the explanation given in the YouTube video linked above, but with a few differences:

  • Uses an empty C++ project instead of a Windows desktop application.
  • Uses 64 bit library instead of 32 bit.
  • The app does not have a button, list-box, etc.

Download and install wxWidgets following the procedure from YouTube video linked above. Be sure to create the environment variable as shown in the video.

Steps:

  • Create empty C++ project
  • Add code for minimal app
  • Configure project to use wxWidgets library
  • Create project template

1. Create Empty C++ Project

From the menu-bar in VS, select Files -> New -> Project – this will open the Create a new project dialog:

Select Empty Project then select Next.

Enter a Project Name and select Create to generate the project.

2. Add Code for Minimal App

Once the project has generated, the Solution Explorer should look like this (with Project1 being replaced by the project name entered above):

RMB on the project name in the Solution Explorer to open a context menu:

From the context menu, select Add -> New Item – the Add New Item dialog should open:

Select Header File (.h) and then enter a name. In this case, the file name used was cMain.h

Enter the following code into the header file:

#pragma once
#include <wx/wx.h>

class MyProjectApp : public wxApp
{
public:
        virtual bool OnInit() override;
};

The IntelliSense will not be happy, and there will be red squiggly lines under wxApp, etc. Something like this:

This will be fixed once we add a path to the wxWindows library.

Add another file using Add -> New Item, only this time create a source code file by choosing file type C++ File (.cpp). Name the file using the same file name as the header file, but change the extension to .cpp.

Enter the following into the source code file:

#include "cMain.h"

bool MyProjectApp::OnInit()
{
    wxFrame* mainFrame = new wxFrame(nullptr, wxID_ANY, L"MyProject");
    mainFrame->Show(true);
    return true;
}
wxIMPLEMENT_APP(MyProjectApp);

3. Configure Project to Use wxWidgets Library

RMB on the project name in the Solution Explorer to open the context menu:

From the context menu, select Properties to open the Property Page dialog:

Along the top of the dialog, there is a drop-down to select which configurations any property changes should apply. Select All Configurations from the Configuration drop-down.

Select C/C++ -> General in the Configuration Properties tree (panel on the left side of dialog).

For the Select Additional Include Directories property, enter $(WXWIN)\include; $(WXWIN)\include\msvc

Note: $(WXWIN) is an environmental variable created during the wxWidgets tutorial in the YouTube video linked above.

Select C/C++ -> Precompiled Headers in the Configuration Properties tree:

For the Precompiled Header property, choose Not Using Precompiled Headers from the drop-down.

Select Linker in the Configuration Properties tree:

For the Additional Library Directories property, enter $(WXWIN)\lib\vc_x64_lib

Note: This is the 64 bit static library, rather than the 32 bit static library used in the video tutorial.

Select Linker -> System in the Configuration Properties tree:

For the SubSystem property, select Windows (/SUBSYSTEM:WINDOWS) from the pull-down (if needed, it may already be set to this).

Select OK.

The project should build and run without error.

The app should look like this:

Close the app and save the project (if you haven’t already).

4. Create Project Template

From the menu bar, select Project -> Export Template – the Export Template Wizard should open:

Select Next.

Enter a Template name. Select Finish to create the template.

The template should now be available when creating new projects, although you will need to select All languages from the Create a new project dialog to find it. If, for example, the template was named wxWidgets, then it should appear in the Create a new project dialog like this:

Select wxWidgets and then Next and proceed as usual to start a new project.

Leave a comment

Design a site like this with WordPress.com
Get started