目录
应用版本
- VS2022
- wxWidgets-3.2.4
安装步骤
- 在wxWidgets官网下载Windows ZIP版本下载 - wxWidgetshttps://wxwidgets.org/downloads/
- 解压到自定文件夹
- 找到解决方案
在wxWidgets-3.2.4\build\msw目录下找到.sln解决方案
作者的VS是2022版本,所以编译wx_vc17.sln(作者在编译时遇到几次缺失文件的情况,如果大家遇到建议多下载几次试一下,也欢迎大佬提出解决方案) - 编译解决方案
打开.sln文件后,选择dubug x64管理器,依次点击生成-批生成-全选-生成,等待运行结束(大概需要十几分钟,编译后的文件夹大约15G) - 添加环境变量
新建系统变量,作者的设置为
变量名:WXWIN
地址为D:\wxWidgets-3.2.4 - 调整VS设置
新建Windows桌面应用程序,点击项目-属性,按照下图进行修改
测试
删除右侧头文件,源文件和资源文件。右键解决方案,依次点击添加-类,如图所示
将下面的代码复制到test.cpp中
// 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!");
}
运行结果如下