开发者

Loading animated GIFs from resource file in wxWidgets

I am trying to embed an animated GIF image into a wxWidgets C++ program. I am able to load the image from file and display it like so:

wxAnimationCtrl *an = new wxAnimationCtrl(this, wxID_ANY,开发者_JS百科 wxAnimation(wxT("image.gif"), wxANIMATION_TYPE_ANY), wxPoint(150,0));
an->Play();

But I would rather have the GIF image in my resource.rc file, so that it is compiled into the executable. How would I do this?


You can try to use wxMSWResources or wxLoadUserResource function, load GIF resource to memory, then obtain wxMemoryInputStream and then use wxAnimation::Load() and pass that input stream to that function


m_ani = new wxAnimationCtrl();
const void* data = NULL;
size_t outLen = 0;

// load the icon directory resource
if ( !wxLoadUserResource(&data, &outLen, "ID_WAIT", RT_RCDATA) )
{
    wxLogError(_("Failed to load icons from resource"));
}
else
{
    wxMemoryInputStream stream(data, outLen);
    if (m_ani->Load(stream))  m_ani->Play();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜