下载
https://www.wxwidgets.org/downloads/
下载压缩包即可
编译
vs 直接编译
打开 build\msw
目录下的 sln
文件
vs发布版本与vc版本对应关系: vs发布版本与vc版本对应关系
vs发布包版本 | vc版本 |
---|---|
Visual Studio 2003 | VC7 |
Visual Studio 2005 | VC8 |
Visual Studio 2008 | VC9 |
Visual Studio 2010 | VC10 |
Visual Studio 2012 | VC11 |
Visual Studio 2013 | VC12 |
Visual Studio 2015 | VC14 |
Visual Studio 2017 | VC15 |
Visual Studio 2019 | VC16 |
Visual Studio 2022 | VC17 |
cmake 结合 vs
在 wxWidgets
跟目录下新建 build
, 然后用 cmake-gui
打开 cmake 图形界面
点击 Generate
之后打开 build\msw\wx_vc17.sln
生成->批生成
全选->重新生成
大约需要 30 分钟
新建 hello world 前的准备
新建一个目录, 将 include 目录和lib目录复制过去
配置环境变量 wx_win
, 值为include
与lib
所在目录: E:\program\wx_wdigets_3.2.2.1
hello world
editor config
[*]
guidelines = 120
[*.{cpp,c,h}]
charset = charset = utf-16le
indent_style = space
indent_size = 4
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
tab_width = 4
代码
// wxWidgets "Hello World" Program
// For compilers that support precompilation, includes "wx/wx.h".
#define WXUSINGDLL
// #define __WXMSW__
// #define _UNICODE
#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, "第一个窗口")
{
wxMenu* menuFile = new wxMenu;
menuFile->Append(ID_Hello, "&你好...\tCtrl-H",
"此菜单的提示文本显示在状态栏");
menuFile->AppendSeparator();
menuFile->Append(wxID_EXIT);
wxMenu* menuHelp = new wxMenu;
menuHelp->Append(wxID_ABOUT);
wxMenuBar* menuBar = new wxMenuBar;
menuBar->Append(menuFile, "文件(&F)");
menuBar->Append(menuHelp, "帮助(&H)");
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!");
}
项目属性设置
修改输出目录与中间目录
所有配置, 所有平台
$(SolutionDir)$(ProjectName)\$(Platform)\$(Configuration)\
添加头文件目录
所有配置, 所有平台
$(wx_win)\include\msvc
$(wx_win)\include
添加库目录
注意, win32与x64 不同
win32
$(wx_win)\lib\vc_dll
x64
$(wx_win)\lib\vc_x64_dll
修改子系统
dll 文件的复制
因为使用的时动态库形式, 所以运行时需要动态库文件, 添加生成事件
所有配置, 所有平台
用于 MSBuild 命令和属性的常用宏
python $(SolutionDir)$(ProjectName)\copylib.py $(Platform) $(Configuration) $(SolutionDir)$(ProjectName)
python 脚本
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
from shutil import copyfile
wx_env_name='wx_win'
dll_dict={
# 'w