/// wxInc.h
#ifndef _WX_INC_H_
#define _WX_INC_H_
#define __WXMSW__ /// 使用windows平台
#define WXUSINGDLL /// 使用动态链接库
#ifdef _DEBUG
#define __WXDEBUG__ /// 使用WxWidgets调试
#endif //_DEBUG
#include "wx/config.h"
#include "wx/wx.h" /// 使用WxWidgets通用功能和类
#include "wx/aui/aui.h" /// 使用AUI
#include "wx/artprov.h" /// 使用预定义的图标资源
#endif ///_WX_INC_H_
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
简单窗口程序
最简单的WxWidgets窗口程序需要2个类:
(1)wxApp类,代表了应用程序,负责消息循环。
(2)wxFrame,代表了窗口,处理各类窗口事件。
下面创建一个简单的窗口程序。程序运行效果如下图所示。
简单窗口程序创建步骤如下:
(1)从wxApp派生用户类MyApp。
wxApp采用了类似MFC的宏定义和处理机制,通过DECLARE_APP()和IMPLEMENT_APP()两个宏声明和定义程序全局变量(也就是程序的入口点)。
/// MyApp.h
#include "wxInc.h"
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
DECLARE_APP(MyApp)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
如未声明DECLARE_APP()和IMPLEMENT(),则编译时会报错如下:
MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用
(2)重载wxApp::OnInit函数,在该函数内新建和显示主窗口。
/// MyApp.cpp
#include "MyApp.h"
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
/// 1.创建窗口
wxFrame * mainWnd = new wxFrame(NULL, wxID_ANY, wxT("main window"));
/// 2.将窗口设置为程序主窗口
SetTopWindow(mainWnd);
/// 3.显示窗口。
mainWnd->Show(true);
return true;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
常见问题处理:
问题1、提示 丢失 wxbase30u_vc100_x64.dll
问题分析:系统中确实没有这个文件
解决办法:下载wxMSW-3.0.3_vc110_ReleaseDLL.7z,这里面有release所需要的dll文件,解压后,拷贝到
C:\wxWidgets-3.0.3\lib\vc_x64_dll目录下即可
下载地址:https://github.com/wxWidgets/wxWidgets/releases/tag/v3.0.3
2、提示:fatal error C1083: Cannot open include file: '../../../lib/vc_x64_lib/mswud/wx/setup.h': No such file or directory
解决办法:
- 预处理器定义:项目“属性→配置属性→C++→预处理器→预处理器定义”增加 WXMSW_、WXUSINGDLL。
参考文章:http://blog.csdn.net/penny_hardaway/article/details/44620111