VS2017-wxWidgets : 搭建Win10-VS2017的wxWidgets開發環境(32位/x86)

Visual Studio 版本:15.8.1
wxWidgets 版本: 3.1.1html

  • Step 1. File -> New -> Project -> Windows Destop Application
    建立默認的Windows窗口應用,自動生成$app.cpp文件,$app爲建立工程的Name
  • Step 2. 拷貝下述代碼,覆蓋Step 1生成的cpp文件
  • Step 3. Project -> $app Proterties -> C/C++ -> Precompiled Headers -> Precomplied Header
    修改成Not Using Precompiled Headers,關閉stdafx.h預編譯頭文件
  • Step 4. Project -> $app Proterties -> C/C++ -> Additional Include Directories
    增長$wxWidgetsPath\include $wxWidgetsPath爲安裝wxWidgets的根目錄路徑
  • Step 5. Project -> $app Proterties -> Linker -> General -> Additional Library Directories
    增長$wxWidgetsPath\lib\vc_lib
  • Step 6. Project -> $app Proterties -> Linker -> Input -> Additional Dependencies
    按照實際依賴需求,增長lib文件,本教程添加以下(部分可能爲冗餘lib文件)c++

    wxmsw31ud_adv.lib wxmsw31ud_core.lib wxbase31ud.lib
    wxbase31ud_net.lib wxmsw31ud_html.lib wxbase31ud_xml.lib
    wxmsw31ud_aui.lib wxmsw31ud_gl.lib wxmsw31ud_media.lib
    wxmsw31ud_propgrid.lib wxmsw31ud_qa.lib wxmsw31ud_ribbon.lib
    wxmsw31ud_richtext.lib wxmsw31ud_stc.lib wxmsw31ud_xrc.lib
    wxscintillad.lib wxtiffd.lib wxjpegd.lib wxpngd.lib
    wxzlibd.lib wxexpatd.lib winmm.lib comctl32.lib rpcrt4.lib
    wsock32.lib odbc32.lib

上述配置能夠選定VS2017配置爲Debug或Release,具體應用Build時候選擇相應的配置模式便可。切記要選擇wxWidgets編譯時候相應的系統位數(32位),即VS2017的x86。64位(x64)暫未成功
配置完畢之後,能夠成功Build或Debug,並看到wxWidgets的Hello World程序。app

成功編譯的截圖:框架

clipboard.png

wxWidgets: 官方「Hello World"教程ui

#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);

// 應用的Init事件句柄
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!");
}

// Exit事件句柄
void MyFrame::OnExit(wxCommandEvent& event)
{
    Close(true);
}

// About事件句柄
void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxMessageBox("This is a wxWidgets' Hello world sample",
        "About Hello World", wxOK | wxICON_INFORMATION);
}

// Hello事件句柄
void MyFrame::OnHello(wxCommandEvent& event)
{
    wxLogMessage("Hello world from wxWidgets!");
}
相關文章
相關標籤/搜索