wxWidgets搭配slickedit和code::blocks进行跨平台GUI开发

最近没事,想学wxWidgets,主要由于它跨平台。这东西和MFC有太多的相像,但比MFC简单很多。如果大家感兴趣就学习学习吧。只是相对文档比较少。我会弄的两个环境一种是wxWidgets搭配code::blocks。以下所有都来自互联网。我只整理了一下。希望文章的作者看到不会责。我的wxWidgets安装目录是C:/wxWidgets2.8

wxWidgets 界面库
wxwidgets 是一个c++编写的用来提供gui开发的框架。它包含一个可以支持现今几乎所有操作系统(Version 2 currently supports all desktop versions of MS Windows, Unix with GTK+, Unix with Motif, and MacOS. An OS/2 port is in progress.)的GUI库和其他一些很有用的工具,提供了类似MFC的功能。
而且,特别要说一下,这个c++lib还的新版本还提供了对掌上电脑的支持。当然,说到这里很多人会想到java队多系统的支持,其实这是不一样的,java的跨平台是建立在“中间代码”的基础上的,就是说需要在目标平台上安装java解释器;但是wxwidgets是c++库,经过编译后,他提供的是native级的机器码,在gui编程方面,这可是意味着很大的不同!官方网址:http://www.wxwidgets.org/
wxWidgets 与其它跨平台的gui库相比有如下优点:
1、是免费的,无论对于个人还是商业应用;
2、支持的操作系统相当全面;
3、大量使用宏,也就是说,编译出来的代码尽量使用目标操作系统的 native 的 gui 样式;
4、支持的编译器各类多;
5、应用广泛,目前有很多 gui 项目都是建立在 wxWidgets 之上的。

到其官方网站下载最新版本的 wxWidgets,目前最新版本为2.8.0,解压到C:/wxWidgets 2.8.0目录下。打开命令行界面[开始|运行,cmd],进入C:/wxWidgets 2.8.0/build/msw 目录,分别输入如下命令行:
清理:  mingw32-make -f makefile.gcc clean
Release:mingw32-make -f makefile.gcc MONOLITHIC=0 SHARED=1 UNICODE=1 BUILD=release
Debug:  mingw32-make -f makefile.gcc MONOLITHIC=0 SHARED=1 UNICODE=1 BUILD=debug
分别 build release 和 debug 版本的库。
编译产生的临时文件分别在 msw mswd mswu mswud
四个子目录中,这些是为了在调整设置后重新编译时节约时间的,若不想重新编译可以把它们删掉。而最终产生的lib 文件已经被拷贝到了 %WXPATH%/lib/vc_lib下。其中每套库还有一个配置文件,分别在%WXPATH%/lib/vc_lib 下的 msw mswd mswu mswud
四个目录中,这些配置文件里包含许多可以调整的预编译选项,具体可以参考相关文档。
到此为止,wxWidgets库已经编译好了。
详细参数说明看文件 c:/wxWidgets 2.8.0/build/msw/config.gcc
详细安装说明看文件 c:/wxWidgets 2.8.0/docs/msw/install.txt
如果不想自己编译,可以到http://wxpack.sourceforge.net/Main/HomePage下载已经编译好的库(wxPack)的最新版本,根据需要安装。

makefile.gcc后边的属性项目在install.txt文件的后边写着了,帅哥用过的也就是那么几个常用的,我这里大概说一下。

Basic options
-------------

BUILD=debug
编译调试版本,因为加入了调试信息,所以文件比较大。
  Builds debug version of the library (default is 'release'). This affects
  name of the library ('d' is appended), __WXDEBUG__ is defined and debug
  information compiled into object files and the executable.

SHARED=0
生成动态链接库的版本。动态链接库是很有用的,特别是使用LGPL的开发库的时候,都要变成动态库,才可以商业用。
  Build static libraries instead of DLLs. By default, DLLs are built
  (SHARED=1).

UNICODE=1
本人是中国人,自然要选这个,就是学的时候要注意的东西多一写,但总比以后不习惯强。
  To build Unicode versions of the libraries, add UNICODE=1 to make invocation
  (default is UNICODE=0). If you want to be able to use Unicode version on
  Windows9x, you will need to set MSLU=1 as well.

  This option affect name of the library ('u' is appended) and the directory
  where the library and setup.h are store (ditto).

WXUNIV=1
就是不让wx使用native的样式,使用统一的样式——个人感觉不好看,但是后项开发的时候会比较方便,以为不用考虑各种gui元素的定位引起问题了。
  Build wxUniversal instead of native wxMSW (see
  http://www.wxwidgets.org/wxuniv.htm for more information).

Advanced options
----------------

MONOLITHIC=1
把所有的库都变在一个文件中。
  Starting with version 2.5.1, wxWidgets has the ability to be built as
  several smaller libraries instead of single big one as used to be the case
  in 2.4 and older versions. This is called "multilib build" and is the
  default behaviour of makefiles. You can still build single library
  ("monolithic build") by setting MONOLITHIC variable to 1.

USE_GUI=0
不用gui模式,编写命令行的程序。
  Disable building GUI parts of the library, build only wxBase components used
  by console applications. Note that if you leave USE_GUI=1 then both wxBase
  and GUI libraries are built. If you are building monolithic library, then
  you should set wxUSE_GUI to 1 in setup.h.

USE_OPENGL=1
自带opengl支持
  Build wxmsw25_gl.lib library with OpenGL integration class wxGLCanvas.
  You must also modify your setup.h to #define wxUSE_GLCANVAS 1. Note that
  OpenGL library is always built as additional library, even in monolithic
  build!

USE_ODBC=1
自带odbc支持
  Build two additional libraries in multilib mode, one with database
  classes and one with wxGrid database support. You must
  #define wxUSE_ODBC 1 in setup.h

USE_HTML=0
不用html库
  Do not build wxHTML library. If MONOLITHIC=1, then you must also
  #define wxUSE_HTML 1 in setup.h.

USE_XRC=0
不用xrc库。xrc是wx为了避免在不同的gui系统上程序元素之间的配合特别是定位的问题而提供的基于XML的用户界面标记语言,通过定义不同系统上不同的xml样式,来解决问题,有点类似于换肤。和xul还有xaml有点类似。
  Do not build XRC resources library. If MONOLITHIC=1, then you must also
  #define wxUSE_HTML 1 in setup.h.

RUNTIME_LIBS=static
不太明白。
  Links static version of C and C++ runtime libraries into the executable, so
  that the program does not depend on DLLs provided with the compiler (e.g.
  Visual C++'s msvcrt.dll or Borland's cc3250mt.dll).
  Caution: Do not use static runtime libraries when building DLL (SHARED=1)!

MSLU=1
不是想找麻烦开发win98程序的人就不用管了。
  Enables MSLU (Microsoft Layer for Unicode). This setting makes sense only if
  used together with UNICODE=1. If you want to be able to use Unicode version
  on Windows9x, you will need MSLU (Microsoft Layer for Unicode) runtime DLL
  and import lib.  The former can be downloaded from Microsoft, the latter is
  part of the latest Platform SDK from Microsoft (see msdn.microsoft.com for
  details). An alternative implementation of import library can be downloaded
  from http://libunicows.sourceforge.net - unlike the official one, this one
  works with other compilers and does not require 300+ MB Platform SDK update.

DEBUG_FLAG=0
DEBUG_FLAG=1
  If set to 1, define __WXDEBUG__ symbol, append 'd' to library name and do
  sanity checks at runtime. If set to 0, don't do it. By default, this is
  governed by BUILD option (if 'debug', DEBUG_FLAG=1, if 'release' it is 0),
  but it is sometimes desirable to modify default behaviour and e.g. define
  __WXDEBUG__ even in release builds.

DEBUG_INFO=0
DEBUG_INFO=1
  Same as DEBUG_FLAG in behaviour, this option affects whether debugging
  information is included in the executable or not.

VENDOR=<your company name>
  Set this to a short string identifying your company if you are planning to
  distribute wxWidgets DLLs with your application. Default value is 'custom'.
  This string is included as part of DLL name. wxWidgets DLLs contain compiler
  name, version information and vendor name in them. For example
  wxmsw250_core_bcc_custom.dll is one of DLLs build using Borland C++ with
  default settings. If you set VENDOR=mycorp, the name will change to
  wxmsw250_core_bcc_mycorp.dll.

CFG=<configuration name>
  Sets configuration name so that you can have multiple wxWidgets builds with
  different setup.h settings coexisting in same tree. See "Object and library
  directories" below for more information.

编译好之后,会在E:/CPPtools/wxWidgets/build/msw/gcc_mswudll 生成编译的中间文件,可以删除。
在E:/CPPtools/wxWidgets/lib/gcc_lib 里找到需要的.a文件,这就是我们的编译成果351m大小。
当然,也可以在samples目录下便直接使用这个目录下的makefile来编译所有的sample,但要注意,有些samples演示
的时特殊设置下的功能,所以学要编译使用此种属性的wx库文件。


SlickEdit的设置
我用的版本是SlickEdit Version 12.0.3.0
打开SlickEdit,File->New,点Project->Customize->New,New package name里填wxWidgets或者其它你喜欢的名字,下面Copy settings from选择GNU C/C++ Wizard。
把Settings for:设置为debug或通过Build菜单中的GNU C Option菜单项中的Settings for:设置为debug。
选中Directories把C:/wxWidgets2.8/include/ 与C:/wxWidgets2.8/lib/gcc_lib/mswud/添加到Includes中,我喜欢把‘.’也添加进去代表工程当前路径。
然后选中Build,点击GNU C Options...会出现新对话框:
选中Compile:这是关于编译的设置
把NOPCH _UNICODE __WXDEBUG__ __WXMSW__ HAVE_W32API_H添加到Preprocessor Defines里,这些都是一些宏的定义。把-mthreads -Wno-ctor-dtor-privacy添加到Other Options里。这些设置会作为编译时的参数,所以要注意当中的空格。
选中Code Generation,把Produce debugging information(-g)前面勾选。Level of optimization为None,Level of debug code为Default。
选中Link:这是关于连接的设置
把-lwxmsw28ud_core -lwxbase28ud -lwxtiffd -lwxjpegd -lwxpngd -lwxzlibd -lwxregexud -lwxexpatd -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32添加到Libraries,这些都是库的名字。
如库文件为libXXX.a则他的库名为XXX,也就是去了头的lib与尾。-l是连接时的参数。前面的是我编译出来的库名,不同设置编译出来的库名会有所区别,后面的那些32结尾的是MinGW的库名。开始时我没加这个,所以怎么弄都没通过,白白花了我好几天时间。
把-mthreads -Wl,--subsystem,windows -mwindows -LC:/wxWidgets2.8/lib/gcc_lib添加到Other Options里。其中-L后面的是我的库的路径,你需要按你的实况情况来设置。
Directories已经设置好了,所以选中Warnings:这是错误输出的设置
把-W与-Wall勾上,其它的按需要设置。
把Settings for:设置为release或通过Build菜单中的GNU C Option菜单项中的Settings for:设置为release。
选中Directories:把C:/wxWidgets2.8/include/ 与C:/wxWidgets2.8/lib/gcc_lib/mswu/添加到Includes里。注意添加的是mswu而非debug的mswud。
同样选中Tools:
再选中Build->Options,在新对话框里设置相关的东西。
选中Compile:
把HAVE_W32API_H __WXMSW__ _UNICODE NOPCH加到Preprocessor Defines里。把-mthreads -Wno-ctor-dtor-privacy添加到Other Options。
选中Code Generation:
把Level of optimization设置为Med。把-g前面的勾去了。
选中Link:
把-lwxmsw28u_core -lwxbase28u -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32加到Libraries/Objects里。
把-mthreads -Wl,-subsystem,windows -mwindows -LC:/wxWidgets2.8/lib/gcc_lib加到Other Options里。同样的-L后面跟的是你的库的路径。
选中Warnings:
把-W与-Wall打开。把所有的warning messages都显示出来。
设置好了。

个人感觉还是slickedit在代码方面强大一些,但毕竟不是免费的。其次就是code::blocks,它的主页是http://www.codeblocks.org/ 它在代码要比slickedit弱一些,但在窗体设计方面要比slickedit强,它的背后有一个勤劳的团队,祝code::blocks的明天越来越好。slickedit好像对wxWidgets支持的不是太完美。题外话如果想要slickedit的话请上我的资源上找。如果你的生活很宽裕的话就不用找了,还是支持一回正版吧,但我是穷人,真的没办法

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值