wxwidgets用xml来描述界面,在程序里获取 变量和事件
如果对界面美观程序比较高,手写代码是不可避免的。
但如果做的是一些像只是为了显示、控制之类的程序,可能更快的把程序捣鼓出来就好了。
wxwidgets有这样的一个功能,就是能用xml写成界面就能显示
编辑xrc的工具是wxformbuilder,开源免费的,也足够用了,我一开始没找到怎么生成xrc,后来某次偶然看到了下面....原来有c++,py,xrc的生成。
wxwidgets里有个例子,叫xrcdemo
大体是是这样。
平时创建wxwidgets程序,我们一般用wxframe,wxdialog
拿wxframe来举例,我们一般从wxfrrame派生,然后在初始化函数里创建控件。
MyFrame::MyFrame(wxWindow* parent)
{
wxXmlResource::Get()->LoadFrame(this, parent, wxT("main_frame"));
}
而现在只要调用这一句就够了。
事件处理方面也有所变动。
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(XRCID("unload_resource_menuitem"), MyFrame::OnUnloadResourceMenuCommand)
EVT_MENU(wxID_ABOUT, MyFrame::OnAboutToolOrMenuCommand)
END_EVENT_TABLE()
获得相关的控件:
wxAnimationCtrl *ctrl = XRCCTRL(*win, "controls_animation_ctrl", wxAnimationCtrl);
加载xml的地方一般在app::init里面,像这样子
wxXmlResource::Get()->InitAllHandlers();
// Load all of the XRC files that will be used. You can put everything
// into one giant XRC file if you wanted, but then they become more
// diffcult to manage, and harder to reuse in later projects.
// The menubar
if (!wxXmlResource::Get()->Load(wxT("rc/menu.xrc")))
return false;
现在还有个问题,就是缺省对中文支持不好,这个我明天来想个办法。
相关文档:
XML文件的解析--libxml库函数解释[转]
libxml(一)
摘要
Libxml是一个有免费许可的用于处理XML、可以轻松跨越多个平 ......
Query:
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath(".\\db\\dbGuest.xml"));
//User是XML根节点,Name字节点
lbEmail.Text =
doc.SelectSingleNode("//User ......
Internet 的应用正在不断地扩大,但我们的 Internet 编程方式还处于石器时代。Internet 用户就像老式主机的分时终端上的用户一样,他们从一个受保护的资源请求信息,然后等待回应。你从正在浏览的 Internet 站点上接收的信息由它希望提供给你的、基于 HTML 的信息组成的。
但是,同远程 Web 站点进行交互式操作是不是 ......
using System;
using System.Xml;
namespace ReadXMLfromFile
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader ("books.xml");
......