vs2022 wxWidgets

打印 上一主题 下一主题

主题 549|帖子 549|积分 1657

下载

https://www.wxwidgets.org/downloads/
下载压缩包即可

编译

打开 build\msw 目录下的 sln 文件

vs发布版本与vc版本对应关系: vs发布版本与vc版本对应关系
vs发布包版本vc版本Visual Studio 2003VC7Visual Studio 2005VC8Visual Studio 2008VC9Visual Studio 2010VC10Visual Studio 2012VC11Visual Studio 2013VC12Visual Studio 2015VC14Visual Studio 2017VC15Visual Studio 2019VC16Visual Studio 2022VC17生成->批生成

全选->重新生成

大约需要 30 分钟
新建 hello world 前的准备

新建一个目录, 将 include 目录和lib目录复制过去

配置环境变量 wx_win, 值为include与lib所在目录: E:\program\wx_wdigets_3.2.2.1
hello world

editor config
  1. [*]
  2. guidelines = 120
  3. [*.{cpp,c,h}]
  4. charset = charset = utf-16le
  5. indent_style = space
  6. indent_size = 4
  7. end_of_line = lf
  8. trim_trailing_whitespace = true
  9. insert_final_newline = true
  10. tab_width = 4
复制代码
代码
  1. // wxWidgets "Hello World" Program
  2. // For compilers that support precompilation, includes "wx/wx.h".
  3. #define WXUSINGDLL
  4. // #define __WXMSW__
  5. // #define _UNICODE
  6. #include <wx/wxprec.h>
  7. #ifndef WX_PRECOMP
  8. #include <wx/wx.h>
  9. #endif
  10. class MyApp : public wxApp
  11. {
  12. public:
  13.     virtual bool OnInit();
  14. };
  15. class MyFrame : public wxFrame
  16. {
  17. public:
  18.     MyFrame();
  19. private:
  20.     void OnHello(wxCommandEvent& event);
  21.     void OnExit(wxCommandEvent& event);
  22.     void OnAbout(wxCommandEvent& event);
  23. };
  24. enum
  25. {
  26.     ID_Hello = 1
  27. };
  28. wxIMPLEMENT_APP(MyApp);
  29. bool MyApp::OnInit()
  30. {
  31.     MyFrame* frame = new MyFrame();
  32.     frame->Show(true);
  33.     return true;
  34. }
  35. MyFrame::MyFrame()
  36.     : wxFrame(NULL, wxID_ANY, "第一个窗口")
  37. {
  38.     wxMenu* menuFile = new wxMenu;
  39.     menuFile->Append(ID_Hello, "&你好...\tCtrl-H",
  40.         "此菜单的提示文本显示在状态栏");
  41.     menuFile->AppendSeparator();
  42.     menuFile->Append(wxID_EXIT);
  43.     wxMenu* menuHelp = new wxMenu;
  44.     menuHelp->Append(wxID_ABOUT);
  45.     wxMenuBar* menuBar = new wxMenuBar;
  46.     menuBar->Append(menuFile, "文件(&F)");
  47.     menuBar->Append(menuHelp, "帮助(&H)");
  48.     SetMenuBar(menuBar);
  49.     CreateStatusBar();
  50.     SetStatusText("Welcome to wxWidgets!");
  51.     Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
  52.     Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
  53.     Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
  54. }
  55. void MyFrame::OnExit(wxCommandEvent& event)
  56. {
  57.     Close(true);
  58. }
  59. void MyFrame::OnAbout(wxCommandEvent& event)
  60. {
  61.     wxMessageBox("This is a wxWidgets Hello World example",
  62.         "About Hello World", wxOK | wxICON_INFORMATION);
  63. }
  64. void MyFrame::OnHello(wxCommandEvent& event)
  65. {
  66.     wxLogMessage("Hello world from wxWidgets!");
  67. }
复制代码
项目属性设置

修改输出目录与中间目录

所有配置, 所有平台
$(SolutionDir)$(ProjectName)\$(Platform)\$(Configuration)\

添加头文件目录

所有配置, 所有平台
  1. $(wx_win)\include\msvc
  2. $(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 脚本
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. import os
  5. from shutil import copyfile
  6. wx_env_name='wx_win'
  7. dll_dict={
  8.     # 'wxbase322u':'net',
  9.     'wxbase322u':'',
  10.     # 'wxbase322u':'xml',
  11.     # 'wxmsw322u':'adv',
  12.     # 'wxmsw322u':'aui',
  13.     'wxmsw322u':'core',
  14.     # 'wxmsw322u':'gl',
  15.     # 'wxmsw322u':'html',
  16.     # 'wxmsw322u':'media',
  17.     # 'wxmsw322u':'propgrid',
  18.     # 'wxmsw322u':'qa',
  19.     # 'wxmsw322u':'ribbon',
  20.     # 'wxmsw322u':'richtext',
  21.     # 'wxmsw322u':'stc',
  22.     # 'wxmsw322u':'webview',
  23.     # 'wxmsw322u':'xrc'
  24. }
  25. if __name__ == "__main__":
  26.     platform = sys.argv[1]
  27.     configuration = sys.argv[2]
  28.     proj_dir = sys.argv[3]
  29.     wx_path = os.getenv(wx_env_name)
  30.     # print('wx_path:',wx_path)
  31.     # print('platform:', platform)
  32.     # print('configuration:',configuration)
  33.     # print('proj_dir:',proj_dir)
  34.     for key,value in dll_dict.items():
  35.         dll_name = key
  36.         if 'Debug' == configuration:
  37.             dll_name = dll_name + 'd'
  38.         if 0 == len(value):
  39.             dll_name = dll_name + '_vc_'
  40.         else:
  41.             dll_name = dll_name + '_' + value + '_vc_'
  42.         if 'x64' == platform:
  43.             dll_name = dll_name + 'x64_'
  44.         dll_name = dll_name + 'custom.dll'
  45.         # print('dll_name:',dll_name)
  46.         
  47.         source_dll = wx_path + os.path.sep + 'lib'
  48.         if 'x64' == platform:
  49.             source_dll = source_dll + os.path.sep + 'vc_x64_dll' + os.path.sep + dll_name
  50.         else:
  51.             source_dll = source_dll + os.path.sep + 'vc_dll' + os.path.sep + dll_name
  52.         # print('source_dll',source_dll)
  53.         target_dll = proj_dir + os.path.sep + platform + os.path.sep + configuration  +  os.path.sep + dll_name
  54.         # print('target_dll',target_dll)
  55.         print(source_dll + ' => ' + target_dll)
  56.         if not os.path.exists(target_dll):
  57.             copyfile(source_dll, target_dll)
复制代码
测试效果


  • 删除与解决方案 .sln 同级的构建目录, 比如 x64等, 保持目录清晰干净

分别运行 Debug x86 , Debug x64 , Release x86 , Release x64 验证效果


项目模板

用Visual Studio2019自定义项目模板
将 .editorconfig与copylib.py添加到项目
添加->现有项

注意:

  • 生成的模板文件位于: C:\Users\用户名\Documents\Visual Studio 2022\My Exported Templates
  • 实际使用的模板文件在: C:\Users\用户名\Documents\Visual Studio 2022\Templates\ProjectTemplates
  • 可能编辑模板之后不生效, 需要删除缓存: C:\Users\用户名\AppData\Local\Microsoft\VisualStudio\vs版本号\ComponentModelCache\Microsoft.VisualStudio.Default.cache
效果


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

泉缘泉

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表