Using XRC in wxWidgets based Application for UI design

WxWidgets 相信很多程序员有过类似的经历,想实现一款图形界面的应用软件。核心算法和后台程序都写好后,等到实现界面时总是发现缺乏艺术细胞,对自己设计的界面和对话框等不满意,或者是消耗在挑选控件、配色和布局等繁琐的工作中不能自拔,最终也许会因为的问题而导致放弃整个项目。一款没有优秀界面的应用软件在繁多的类似产品中很难获得用户的喜爱。利用我们可以将很多界面设计工作轻松搞定,而且利用 based resource,规范,可以将界面设计工作和程序分离,独立的文件维护容易,简单直观而且可以使得程序本身只关注于逻辑,何乐而不为呢。

以下包括几个部分介绍,有介绍包括中英文的(摘自网络)和使用步骤,以及几个常用设计工具的链接。

The -based resource system, known as , allows user interface elements such as dialogs, menu bars and toolbars, to be stored in text files and loaded into the application at run-time. files can also be compiled into binary XRS files or C++ code (the former makes it possible to store all resources in a single file and the latter is useful when you want to embed the resources into the executable).

There are several advantages to using resources.

  • Recompiling and linking an application is not necessary if the resources change.
  • If you use a dialog designer that generates C++ code, it can be hard to reintegrate this into existing C++ code. Separation of resources and code is a more elegant solution.
  • You can choose between different alternative resource files at run time, if necessary.
  • The format uses sizers for flexibility, allowing dialogs to be resizable and highly portable.
  • The format is a standard, and can be generated or postprocessed by any program that understands it. As it is based on the standard, existing editors can be used for simple editing purposes.

was written by Vaclav Slavik.

Resource)的设计来源于,它的想法很简单,就是将界面设计的工作从程序中独立出来。具体的做法是,创建单独的文件,负责界面设计,程序运行的时候载入,生成界面。这样做的好处是显而易见的。首先,将繁琐的外观设计代码从程序中去掉,程序更清晰易读。其次,文件独立于程序,程序运行时才调用,因此可以随意更换外观。这种思想并不是的原创,MFC中的RC已经有了,类似的还有HTML和CSS的关系。继承而来,当然也保留了

这里有几点要补充的。一是文件中用到的类名称仍然是中的类名称,换句话说,可以共用文件,第二点要补充的是文件可以编译成二进制文件XRS,或者编译成C++代码。

- http://hi.baidu.com/madrigar/blog/item/e36c21a44c9787f29052ee84.html

 

使用的具体步骤如下:

These are the typical steps for using files in your application.

  • Include the appropriate headers: normally "wx//xmlres.h" will suffice;
  • If you are going to use XRS files, install wxFileSystem ZIP handler first with wxFileSystem::AddHandler(new wxZipFSHandler);
  • call wxXmlResource::Get()->InitAllHandlers() from your wxApp::OnInit function, and then call wxXmlResource::Get()->Load("myfile.") to load the resource file;
  • to create a dialog from a resource, create it using the default constructor, and then load it using for example wxXmlResource::Get()->LoadDialog(&dlg, this, "dlg1");
  • set up event tables as usual but use the XRCID(str) macro to translate from string names to a suitable integer identifier, for example EVT_MENU(XRCID("quit"), MyFrame::OnQuit).

To create an file, you can use one of the following methods.

  • Create the file by hand;
  • use wxDesigner, a commercial dialog designer/RAD tool;
  • use DialogBlocks, a commercial dialog editor;
  • use XRCed, a -based dialog editor that you can find in the /tools subdirectory of the CVS archive;
  • use wxGlade, a GUI designer written in . At the moment it can generate Python, C++ and ;
  • convert WIN32 RC files to with the tool in contrib/utils/convertrc.

A complete list of third-party tools that write to can be found at www.wxwidgets.org/lnk_tool.htm.

It is highly recommended that you use a resource editing tool, since it’s fiddly writing files by hand.

You can use wxXmlResource::Load in a number of ways. You can pass an file (-based text resource file) or a zip-compressed file (extension ZIP or XRS) containing other .

You can also use embedded C++ resources

Further reading: http://docs.wxwidgets.org/2.6.3/wx_xrcoverview.html#xrcconcepts

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

Related posts:

  1. A rough guide for wxWidgets programming
  2. FLTK & the List of Widget toolkits based on C/C++
  3. wxWidgets Programming: Sizer, Frame and Panel
  4. Book: Cross-Platform GUI Programming with wxWidgets (Bruce Perens)(含中英文版本下载地址)
  5. Code::Blocks IDE in openSUSE 11.1编译和安装指南
  6. wxWidget Layout Algorithm Demo - BoxPlanner
  7. CodeLite Initializaion analysis - 初始化流程分析(1)
  8. CodeLite Plugin Internal(2)-Load: 插件加载分析
  9. Singleton模式

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Contact us

Admin: Bryan Wu