April 20, 2024, 12:29:26 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


CToolbar24 crash problem

Started by LarryMc, November 04, 2011, 01:59:04 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

I have been using Sapero's CToolbar24 class for fancy toolbars for several projects, the biggest of which was IWB+.
So I have been using it without any problems for over a year.

It was designed around 16x16 bitmap images in a strip of 16 x whatever.
The toolbar image HAD to be saved as a 24bpp image.

I decide I wanted to convert it to use with 32x32 images still @ 24bpp.

I got all the code converted to display the the 32x32 images in the normal enabled case.

The following routine creates a gray bitmap that is used when the button is disabled.

sub CToolbar32::CreateGrayImage24(HDC dc, HDC dcGray byref, HBITMAP bmGray byref)

DIBSECTION ds
pointer bits
settype bits, char

GetObject(GetCurrentObject(dc, OBJ_BITMAP), len(ds), &ds)

dcGray = CreateCompatibleDC(dc)
bmGray = SelectObject(dcGray, CreateDIBSection(dc, ds.dsBmih, DIB_PAL_COLORS, &bits, ds.dshSection, ds.dsOffset))
if (bmGray)
int PixelCount = (ds.dsBm.bmWidth * ds.dsBm.bmHeight)
memcpy(bits, ds.dsBm.bmBits, PixelCount * 3)  '<<================================================
INT ColorMask = 0
memcpy(&ColorMask, *bits, 3)
while (PixelCount)
if (memcmp(*bits, &ColorMask, 3))
char _color = ((*bits + *bits[1] + *bits[2]) / 6) + 128
if (_color > 192) then _color = 192
memset(bits, _color, 3)
endif
PixelCount--
bits += 3
endwhile
endif
endsub


Remember this block of code works fine with 16x16 but crashes with 32x32 bithmap at the line with the <<======

bits is a pointer used to point to memory
with 16x16 the crashing line copies the 3 color planes of my bitmap (6,656 bytes)
with 32x32 it is suppose to copy 27,124 bytes and it is crashing there

maybe one of ya'll out there can tell me why it is crashing or a work around.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

FoundIt!  False alarm

It appears the software I was using to create the toolbar somehow switched to 8bpp for that specific image.

That only cost me about 4 hours.

Senior moment 4 hours ;D

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library