在 wxWidgets 中使用基于 XML 的资源

● XRC 描述外部资源

#include "wx/wx.h"
#include "wx/xrc/xmlres.h"

bool MyApp::OnInit()
{
wxXmlResource::Get()->InitAllHandlers();
wxXmlResource::Get()->Load(wxT("myframe.xrc"));

wxFrame * frame = wxXmlResource::Get()->LoadFrame(NULL, wxT("frame_name"));
frame->Show(true);

return true;
}

● XRS 二进制资源

$ wxrc -o myframe.xrs myframe.xrc
#include "wx/wx.h"
#include "wx/xrc/xmlres.h"
#include "wx/fs_arc.h"

bool MyApp::OnInit()
{
wxFileSystem::AddHandler(new wxArchiveFSHandler);
wxXmlResource::Get()->InitAllHandlers();
wxXmlResource::Get()->Load(wxT("myframe.xrs"));

wxFrame * frame = wxXmlResource::Get()->LoadFrame(NULL, wxT("frame_name"));
frame->Show(true);

return true;
}

● CPP 内嵌资源

$ wxrc -c -o myframe.cpp myframe.xrc
#include "wx/wx.h"
#include "wx/xrc/xmlres.h"

extern void InitXmlResource();

bool MyApp::OnInit()
{
wxXmlResource::Get()->InitAllHandlers();
InitXmlResource();

wxFrame * frame = wxXmlResource::Get()->LoadFrame(NULL, wxT("frame_name"));
frame->Show(true);

return true;
}

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注