News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

wxWidgets XML resource files

Started by sethjackson, September 29, 2005, 10:10:00 PM

Previous topic - Next topic

sethjackson

I'm trying to load a menu from an .xrc file. Unfortuately I keep getting errors.

main.cpp

#include <wx/xrc/xmlres.h>
#include "main.h"

int idFileQuit = XRCID("idFileQuit");
int idHelpAbout = XRCID("idHelpAbout");

BEGIN_EVENT_TABLE(MainFrame, wxFrame)

EVT_MENU(idFileQuit, MainFrame::OnQuit)

EVT_MENU(idHelpAbout, MainFrame::OnAbout)

END_EVENT_TABLE()

MainFrame::MainFrame(wxFrame *frame, const wxString& title,
                     int xpos, int ypos, int width, int height)
: wxFrame(frame, -1, title, wxPoint(xpos, ypos), wxSize(width, height))
{
wxXmlResource::Get()->InitAllHandlers();

wxXmlResource::Get()->Load(_T("/resources.zip#zip*.xrc"));

CreateMenubar();
}

MainFrame::~MainFrame()
{

}

bool MainFrame::CreateMenubar()
{
wxMenuBar* mbar = 0L;

wxXmlResource *myres = wxXmlResource::Get();

myres->Load(_T("/resources.zip#zip:main_menu.xrc"));

myres->LoadMenuBar(0L, _T("main_menu_bar"));

SetMenuBar(mbar);

return true;
}

void MainFrame::OnQuit(wxCommandEvent& event)
{
Close(true);
}

void MainFrame::OnAbout(wxCommandEvent& event)
{
wxMessageBox(_("wxWidgets Example"), _("Welcome to..."));
}



main_menu.xrc

<?xml version="1.0"?>
<resource>
  <object class="wxMenuBar" name="main_menu_bar">
    <object class="wxMenu" name="file_menu">
      <label>&amp;File</label>     
      <object class="wxMenuItem" name="idFileExit">
        <label>&amp;Quit</label>
        <accel>Ctrl-Q</accel>
        <help>Quit wxWidgets Example</help>
      </object>
    </object>   
    <object class="wxMenu" name="help_men">
      <label>&amp;Help</label>
      <object class="wxMenuItem" name="wxID_ABOUT">
        <label>&amp;About...</label>
        <help>About wxWidgets Example</help>
      </object>     
    </object>
  </object>
</resource>



So wxWidgets tells me "XRC resource 'main_menu_bar' (class 'wxMenuBar') not found!"
It gives me a nice little error box I click on details and it says "can't load resources from file '"/resources.zip#zip:main_menu.xrc' (time)"
It gives me an option to save to a log and here is the log.

16:05:59: Cannot load resources from file '/resources.zip#zip:main_menu.xrc'.
16:05:59: Cannot load resources from file '/resources.zip#zip:main_menu.xrc'.
16:05:59: XRC resource 'main_menu_bar' (class 'wxMenuBar') not found!

What am I doing wrong? This is totally new to me, I have never used wxWidgets before.

mandrav

QuotewxXmlResource::Get()->Load(_T("/resources.zip#zip*.xrc"));

You should change this to relative path, e.g.
wxXmlResource::Get()->Load(_T("resources.zip#zip*.xrc"));
(notice it's "resources" not "/resources")
Be patient!
This bug will be fixed soon...

sethjackson

Quote from: mandrav on September 29, 2005, 11:16:55 PM
QuotewxXmlResource::Get()->Load(_T("/resources.zip#zip*.xrc"));

You should change this to relative path, e.g.
wxXmlResource::Get()->Load(_T("resources.zip#zip*.xrc"));
(notice it's "resources" not "/resources")

I did that still nothing. I keep getting the same error.

Maybe something else is wrong?

Urxae

Did you initialize the zip file handler? If not, wxWidgets has no idea how to get the stuff in a zip file.

On application startup, call wxFileSystem::AddHandler(new wxZipFSHandler); (don't forget to include <wx/filesys.h> and <wx/fs_zip.h>)

HTH

sethjackson

#4
Quote from: Urxae on September 30, 2005, 12:39:15 AM
Did you initialize the zip file handler? If not, wxWidgets has no idea how to get the stuff in a zip file.

On application startup, call wxFileSystem::AddHandler(new wxZipFSHandler); (don't forget to include <wx/filesys.h> and <wx/fs_zip.h>)

HTH

Thanks Urxae that makes sense. Duh  :oops:

EDIT:

Ok so I change


myres->LoadMenuBar(0L, _T("main_menu_bar"));


to


mbar = myres->LoadMenuBar(0L, _T("main_menu_bar"));


and I fixed the .xrc file to have the right XRCID's

:oops: :roll:

Sometimes I need to think before I dive right in to coding.