官网下载wxWidgets
在wxWidgets官网下载Windows ZIP版本
https://wxwidgets.org/downloads/
1.创建一个文件夹,用于解压wxwidgets,解压后如下:
2.在wxWidgets\build\msw目录下找到wx_vc12.sln解决方案,用VS2022打开.
3.VS中点击“生成”–“批生成”
4.“全选”—“生成”
5.等待VS加载完成(第一次需要一些时间,同时会现实生成进度条,后面若再点击生成(不是重新生成),时间会短一点)
由于我之变之前已经生成过了,所以再次点击生成,加载比较快,甚至没有出现生成进度条。
开始配置
1.创建新项目
2.源文件添加一个CPP文件
3.如下打开属性
4.根据下面图示一次更改配置
c++——常规——附加包含目录,依次添加如下两个目录地址:
SDL检查:否
符合模式::否
链接器——常规——附加库目录
预处理器(定义):
WXMSW
_UNICODE
NDEBUG
_CRT_NONSTDC_NO_DEPRECATE
_CRT_SECURE_NO_WARNINGS
“链接器”–“系统”–“子系统”——窗口:
点击“应用”—“确定”。
注意:
如上所示配置和平台的选择要一致。
使用下面代码进行测试:
// 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!");
}
运行成功: