vs2017 搭建 wxWidgets 环境
2018-09-20 本文已影响0人
虚心的锄头
1,下载wxwidgets包并安装,
https://www.wxwidgets.org/downloads/
这里下载的是3.1.1
2, 编译
安装目录

C:\wxWidgets\build\msw\wx.dsw
用VS2017打开wx.dsw,类似如图所示

右击解决方案,点击批生成,勾选所有Debug和Release(可根据需要选择),点击生成进行编译。

此时,wxWidgets-3.0.0\lib\vc_lib目录如下所示,已生成所需库文件,其中u表示Release版本,ud表示Debug版本。

3, 建立一个简单的窗口
创建一个空项目


点击新建项会出现下图:

之后出现:

配置(重点):

1、出现下图,添加头文件:C/C++→常规→附加包含目录(添加头文件在硬盘中的位置)


3、引用库文件:链接器→输入→附加依赖项→添加lib文件

wxbase31ud.lib
wxbase31ud_net.lib
wxbase31ud_xml.lib
wxexpatd.lib
wxjpegd.lib
wxmsw31ud_adv.lib
wxmsw31ud_aui.lib
wxmsw31ud_core.lib
wxmsw31ud_gl.lib
wxmsw31ud_html.lib
wxmsw31ud_media.lib
wxmsw31ud_propgrid.lib
wxmsw31ud_qa.lib
wxmsw31ud_ribbon.lib
wxmsw31ud_richtext.lib
wxmsw31ud_stc.lib
wxmsw31ud_webview.lib
wxmsw31ud_xrc.lib
wxpngd.lib
wxregexud.lib
wxscintillad.lib
wxtiffd.lib
comctl32.lib // 以下4个千万不要忘记添加,否则会报 链接错误 错,
rpcrt4.lib
wxzlibd.lib
odbc32.lib
4、链接器→系统→子系统→窗口

5 预处理器定义
配置一项改为Debug
配置属性->C/C++->预处理器->预处理器定义中添加:
__WXMSW__
__WXDEBUG__
Hello world 代码:
#include "wx\wxprec.h"
#include "wx\wx.h"
#include <iostream>
#include <string>
using namespace std;
#ifndef WX_PRECOMP
#include "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);
// main function this macro is the main function
// create an application instance and starts the program
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",
"Hello string show 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!");
}
运行结果:
