C++ – VS2017 Install wxWidgets

ready

Download source code

download link:http://www.wxwidgets.org/downloads/

Select Source Code > Windows 7z Download

Unzip the source code

Unzip wxWidgets

Compile source code

Open wxWidgets-XXX\build\msw\wx_vc15.sln with VS

Select Debug, DLL Debug, DLL Release, Release respectively

Then click Build > Build Solution

Just wait for the compilation to complete

Sample

ready

Create a new empty project, create Main.cpp, and copy the example on the official website

Address:https://docs.wxwidgets.org/trunk/overview_helloworld.html

// wxWidgets Hello World Program
// For compilers that support precompilation, includes wx/wx.h.
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
    MyFrame();
private:
    void OnHello(wxCommandEvent& event);
    void OnExit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
};
enum
{
    ID_Hello = 1
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame();
    frame->Show(true);
    return true;
}
MyFrame::MyFrame()
    : wxFrame(NULL, wxID_ANY, Hello World)
{
    wxMenu *menuFile = new wxMenu;
    menuFile->Append(ID_Hello, &Hello...\tCtrl-H,
        Help string shown in status bar for this menu item);
    menuFile->AppendSeparator();
    menuFile->Append(wxID_EXIT);
    wxMenu *menuHelp = new wxMenu;
    menuHelp->Append(wxID_ABOUT);
    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append(menuFile, &File);
    menuBar->Append(menuHelp, &Help);
    SetMenuBar(menuBar);
    CreateStatusBar();
    SetStatusText(Welcome to wxWidgets!);
    Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
    Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
    Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
}
void MyFrame::OnExit(wxCommandEvent& event)
{
    Close(true);
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxMessageBox(This is a wxWidgets Hello World example,
        About Hello World, wxOK | wxICON_INFORMATION);
}
void MyFrame::OnHello(wxCommandEvent& event)
{
    wxLogMessage(Hello world from wxWidgets!);
}

Configuration items

Open Project Properties Project > X Properties

Configuration – All configurations

C/C++ > General > Add wxWidgets-XXX\include to additional include directories

C/C++ > General > Add wxWidgets-XXX\demos\life to the additional include directory

C/C++ > Preprocessor > Add WXUSINGDLL to preprocessor definition

Linker > General > Add wxWidgets-XXX\lib\vc_dll to the additional library directory

Configuration – Release

C/C++ > General > Add wxWidgets-XXX\lib\vc_dll\mswu to the additional include directory

Add wxbase31u.lib in Linker > Input > Add Dependencies

Add wxmsw31u_core.lib in Linker > Input > Add Dependencies

Configuration – Debug

C/C++ > General > Add wxWidgets-XXX\lib\vc_dll\mswud to the additional include directory

Add wxbase31ud.lib in Linker > Input > Add Dependencies

Add wxmsw31ud_core.lib in Linker > Input > Add Dependencies

Put into dynamic link library

Put wxbaseXXXu_vc_custom.dll in the project root directory > Release

Put wxmswXXXu_core_vc_custom.dll in the project root directory > Release

Put wxbaseXXXud_vc_custom.dll in the project root directory > Debug

Put wxmswXXXud_core_vc_custom.dll in the project root directory > Debug

The above files are in wxWidgets-XXX\lib\vc_dll

Run program

Completed

About X64

Change Win32 to X64 when compiling source code

When configuring the project, the vc_dll folder is changed to vc_x64_dll

Put the X64 version into the dynamic link library

Reference video

https://www.youtube.com/watch?v=EI2taYkErRg

Post Reply