The palace guide said, change handsome like change a knife
Programmer's compiler to change, basic routines must be re-practiced a few times
Using wxwidgets is not difficult, but you cannot use existing libraries and engineering profiles, and the details must be clear
Get wxwidgets
The official download page, the next 7z or zip file can be
The file "wxwidgets root directory/docs/msw/install.txt" is a compilation documentation that can be used as a reference
Add environment variable Wxwin, the value is the path to the wxwidgets root directory
The path to the wxwidgets root directory does not contain spaces
Increased vs2015 support
VS2015 affects compilation changes, mainly defining the snprintf, and the compiler version is upgraded to 14.
You need to make the following modifications to wxwidgets to compile with vs2015.
%wxwin%\include\msvc\wx\setup.h,66 line, add version support
#elif _MSC_VER == 1900
#define wxCOMPILER_PREFIX vc140
%wxwin%\include\wx\compiler.h,56 line, add version support
#elif __VISUALC__ < 2000
# define __VISUALC14__
In the following three files, find the macro definition of snprintf, comment out
- %wxwin%\src\tiff\libtiff\tif_config.h
- %wxwin%\src\tiff\libtiff\tif_config.vc.h
- %wxwin%\src\zlib\gzguts.h
Compiling library files
Run Start | All Programs |visual Studio 2015|visual Studio tools| VS2015 developer Command Prompt "
Switch to%WXWIN%\BUILD\MSW
32-bit static library debug version
nmake/f MAKEFILE.VC
Library file generated in%wxwin%\lib\vc_lib, file name contains d for debug version
32-bit static library release version
nmake/f MAKEFILE.VC Build=release
Library file generated in%wxwin%\lib\vc_lib, file name does not contain D and debug version differentiated
32-bit dynamic Library Debug version
nmake/f MAKEFILE.VC shared=1
Library file generated in%wxwin%\lib\vc_dll, file name contains d for debug version
32-bit dynamic Library release version
nmake/f MAKEFILE.VC build=release shared=1
Library file generated in%wxwin%\lib\vc_dll, file name does not contain D and debug version differentiated
Run Start | All Programs |visual Studio 2015|visual Studio tools| Windows Desktop Command prompts| VS2015 x64 Native Tools command Prompt
Switch to%WXWIN%\BUILD\MSW
64-bit static library debug version
nmake/f MAKEFILE.VC target_cpu=x64
Library file generated in%wxwin%\lib\vc_x64_lib, file name contains d for debug version
64-bit static library release version
nmake/f MAKEFILE.VC build=release target_cpu=x64
Library file generated in%wxwin%\lib\vc_x64_lib, file name does not contain D and debug version differentiated
64-bit Dynamic Library Debug version
nmake/f MAKEFILE.VC shared=1 target_cpu=x64
Library file generated in%wxwin%\lib\vc_x64_dll, file name contains d for debug version
64-bit dynamic Library release version
nmake/f makefile.vc build=release shared=1 target_cpu=x64
Library file generated in%wxwin%\lib\vc_x64_dll, file name does not contain D and debug version differentiated
"Hello World"
Official source code
// 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(const wxString& title, const wxPoint& pos, const wxSize& size);
private:
void OnHello(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE();
};
enum
{
ID_Hello = 1
};
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Hello, MyFrame::OnHello)
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
wxEND_EVENT_TABLE()
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame("Hello World", wxPoint(50, 50), wxSize(450, 340));
frame->Show(true);
return true;
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(NULL, wxID_ANY, title, pos, size)
{
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!");
}
void MyFrame::OnExit(wxCommandEvent& event)
{
Close(true);
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
wxMessageBox("This is a wxWidgets‘ Hello world sample",
"About Hello World", wxOK | wxICON_INFORMATION);
}
void MyFrame::OnHello(wxCommandEvent& event)
{
wxLogMessage("Hello world from wxWidgets!");
}
Compiling the static library debug scheme
"Project Properties | C/c++| General | Additional Include directories, adding
%wxwin%\include
"Project Properties | linker | general | Additional Library directory", adding
%wxwin%\lib\vc_lib
"Project Properties | linker | input | Additional dependencies", adding
wxbase30ud.lib
wxbase30ud_net.lib
wxbase30ud_xml.lib
wxexpatd.lib
wxjpegd.lib
wxmsw30ud_adv.lib
wxmsw30ud_aui.lib
wxmsw30ud_core.lib
wxmsw30ud_gl.lib
wxmsw30ud_html.lib
wxmsw30ud_media.lib
wxmsw30ud_propgrid.lib
wxmsw30ud_qa.lib
wxmsw30ud_ribbon.lib
wxmsw30ud_richtext.lib
wxmsw30ud_stc.lib
wxmsw30ud_webview.lib
wxmsw30ud_xrc.lib
wxpngd.lib
wxregexud.lib
wxscintillad.lib
wxtiffd.lib
wxzlibd.lib
winmm.lib
comctl32.lib
rpcrt4.lib
wsock32.lib
wininet.lib
It is recommended to add dependencies in this way, instead of writing #pragmma comment, it is convenient to switch different schemes and the code is beautiful.
The last 5 dependencies don't belong to Wxwidgets.
Compile Run, Success ~
Compiling the static library release scheme
The path to the additional library directory is different, to modify
Depending on the name of the library, remove D
Compilation of dynamic library scenarios
"Project Properties | c/c++| Preprocessor | Attach included directory, add
Wxusingdll
Visual Studio 2015 compilation wxwidgets