Search code examples
c++bitmapwxwidgets

Using bitmaps from resource file


I have a toolbar that uses bitmap images. Im using the generic bitmaps from the sample file, and they work perfectly fine.

However when I try to add a new bitmap icon for this instance its close.bmp (it is also correctly sized 16x15 px just like all the other icons) my program gives me errors.

I just need to know how to use bitmaps from a resource file

errors

../../src/msw/toolbar.cpp(799): assert "Assert Failure" failed in 
Realize():invalid tool button bitmap

Cant load bitmap 'close' from resources! Check.rc file.

resource .rc

new BITMAP "bitmaps/new.bmp"
open BITMAP "bitmaps/open.bmp"
save BITMAP "bitmaps/save.bmp"
help BITMAP "bitmaps/help.bmp"
close BITMAP "bitmaps/close.bmp"

.cpp

{
    // Set up toolbar
    enum
    {
        Tool_new,
        Tool_open,
        Tool_save,
        Tool_help,
        Tool_close,
        Tool_Max
    };

    wxBitmap toolBarBitmaps[Tool_Max];

#if USE_XPM_BITMAPS
    #define INIT_TOOL_BMP(bmp) \
        toolBarBitmaps[Tool_##bmp] = wxBitmap(bmp##_xpm)
#else // !USE_XPM_BITMAPS
    #define INIT_TOOL_BMP(bmp) \
        toolBarBitmaps[Tool_##bmp] = wxBITMAP(bmp)
#endif // USE_XPM_BITMAPS/!USE_XPM_BITMAPS



    INIT_TOOL_BMP(new);
    INIT_TOOL_BMP(open);
    INIT_TOOL_BMP(save);
    INIT_TOOL_BMP(help);
    INIT_TOOL_BMP(close);

    toolBar->AddTool(wxID_ANY, wxT("New"), toolBarBitmaps[Tool_new], wxNullBitmap, wxITEM_NORMAL, wxT("New IWEX Project"));
    toolBar->AddTool(wxID_ANY, wxT("Open"), toolBarBitmaps[Tool_open], wxNullBitmap,wxITEM_NORMAL , wxT("Open IWEX Project"));
    toolBar->AddTool(idFileClose, wxT("Close"), toolBarBitmaps[Tool_close], wxT("Close button"), wxITEM_NORMAL);

    toolBar->Realize();

}

Solution

  • So I was able to resolve the issue. The code does not seem to be an issue. It is the bitmap file format. Im not exactly sure why it makes a difference but I was editing photo sizes from GIMP, and I would get issues. The same images if I resize using FastStone image viewer it seems to work right.