开发者

Memory Allocation issue when modifying CreateToolbarEx function with new bitmap

开发者 https://www.devze.com 2023-02-18 20:13 出处:网络
I\'m trying to modify some old code (c++) that uses the CreateToolbarEx function, in an attempt to use a new bitmap and replace our 24x24 pixel toolbar buttons with flashier 36x36 ones.The function I\

I'm trying to modify some old code (c++) that uses the CreateToolbarEx function, in an attempt to use a new bitmap and replace our 24x24 pixel toolbar buttons with flashier 36x36 ones. The function I'm using is as follows:

m_hToolbarWnd = CreateToolbarEx(m_hPagerWnd, ws, ID_TOOLBAR, NUMBERTOOLBARBITMAPS, hInst, IDB_TOOLBAR, tbInitButtons, m_ncButtons, 24, 24, 24, 24, sizeof(TBBUTTON));

I'm able to expand the size of the current toolbar buttons by changing the '24's to '36'开发者_JAVA技巧, but if I change IDB_TOOLBAR to the new toolbar bitmap and run the program I hit a memory access read violation pointing to the CreateToolbarEx function. Am I missing something on how the bitmap is getting its memory allocation or creating the individual buttons? The new toolbar is 1584x36 pixels (44 buttons).


This is old, but hopefully the solution I found will help someone. I had overlooked the fact that I was changing from a 16-bit color bitmap to 24-bit, which I was unable to get CreateToolbarEx to handle. Instead, I had to call CreateWindowEx and create and set the icon ImageList for it. Working code:

m_hToolbarWnd = CreateWindowEx(0L, TOOLBARCLASSNAME, "", ws, 36, 36, 36, 36, m_hPagerWnd, (HMENU) ID_TOOLBAR, hInst, NULL);
SendMessage(m_hToolbarWnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
HBITMAP hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TOOLBAR));
HIMAGELIST hIcons = ImageList_Create(36, 36, ILC_COLOR24, 0, m_ncButtons);
ImageList_Add(hIcons, hBmp, NULL);
SendMessage(m_hToolbarWnd, TB_SETIMAGELIST, 0, (LPARAM) hIcons);
0

精彩评论

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

关注公众号