Click here to Skip to main content
15,843,865 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I inserted a bitmap in toolbar and in this code:
C++
m_toolbar.Create(this);
m_toolbar.LoadToolBar(IDR_TOOLBAR1);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);


I have a crash in m_toolbar.LoadToolBar(IDR_TOOLBAR1);

Code of resource:
IDR_TOOLBAR1            BITMAP                  "res\\toolbar1.bmp"

IDB_BITMAP1             BITMAP                  "res\\scarica_pezzo.bmp"

IDB_BITMAP2             BITMAP                  "res\\bitmap2.bmp"


What I have tried:

Before that, I tried to insert bitmap I didn't have this problem... I improved my question.
Posted
Updated 27-Oct-23 6:31am
v3
Comments
Richard MacCutchan 26-Oct-23 4:19am    
Without more information it is impossible to guess what went wrong. Please show the IDR_TOOLBAR1 resource statements. Also, I do not see where you load the bitmap into the toolbar.

1 solution

You are trying to load a bitmap as a ToolBar resource. A toolbar resource looks like:
C++
IDR_MAINFRAME TOOLBAR DISCARDABLE  16, 15
BEGIN
    BUTTON      ID_FILE_NEW
    BUTTON      ID_FILE_OPEN
    BUTTON      ID_FILE_SAVE
    SEPARATOR
    BUTTON      ID_ENTRY_NEW
    BUTTON      ID_ENTRY_EDIT
    BUTTON      ID_ENTRY_DELETE
    SEPARATOR
    BUTTON      ID_APP_ABOUT
END

You call LoadToolBar to load this resource, and then call CToolBar Class : LoadBitmap | Microsoft Learn[^] to load the matching bitmap. As always you should make use of the documentation to guide you.
 
Share this answer
 
Comments
Member 14594285 26-Oct-23 5:26am    
I tried this:
m_toolbar.Create(this);
m_toolbar.LoadBitmap(IDR_TOOLBAR1);

but it's the same thing
Richard MacCutchan 26-Oct-23 6:53am    
You must load the Toolbar resource first, and the number of elements in the resource must match the number of button images in the bitmap.
Member 14594285 26-Oct-23 8:22am    
I tried this:
m_toolbar.Create(this);
m_toolbar.LoadBitmap(IDB_BITMAP1);
m_toolbar.LoadToolBar(IDR_TOOLBAR1);

RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
Richard MacCutchan 26-Oct-23 9:20am    
Yes, and also still trying to load a bitmap instead of a toolbar resource.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900