accessing bitmaps on an .xrc compiled into .cpp
personaje
personaje at gmail.com
Tue Oct 16 11:31:27 PDT 2007
On 10/16/07, personaje <personaje at gmail.com> wrote:
> On 10/16/07, Jason Dolan <jayson.dolan at gmail.com> wrote:
> > wxXmlResource::Get()->InitAllHandlers();
> > InitXmlResource(); //Or whatever your xmlresource function is
> > called within the dynamically generated cpp file
> > wxFrame *pMyFrame;
> > wxXmlResource::Get()->LoadFrame(pMyFrame, NULL,
> > wxT("The_frames_name"));
> > wxBitmap *pMyBitmap = XRCCTRL(*pMyFrame, "bitmap_name", wxBitmap);
> >
>
> nope, I get an invalid cast from wxWindow* to wxBitmap* : (
and it's OK because XRCCTRL uses findwindow : )
Found it, not as straightforward as I would like but :
---------- code ----------
#define GET_BITMAP_RESOURCE(Url,Bitmap) {
\
wxFSFile *fsfile = wxFileSystem().OpenFile(Url, wxFS_READ | wxFS_SEEKABLE);\
if (fsfile == NULL) {
\
wxLogError(_("XRC resource: Cannot create bitmap from '%s'."),Url); \
Bitmap = wxNullBitmap; } \
else { \
wxImage img(*(fsfile->GetStream())); \
Bitmap = wxBitmap(img); } \
delete fsfile; }
---------- end code ----------
Taken and adapted from xmlres.cpp
Hope it works for someone else!
Regards
More information about the wx-users
mailing list