// BlockBitmap.h
struct BMINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[256];
};
class BlockBitmap
{
public:
BlockBitmap(void);
~BlockBitmap(void);
public:
bool setBitmap(BMINFO* pbmInfo, char* pbmBits);
bool setBitmap(const char* pBuff);
HBITMAP getHBitmap() { return m_Bitmap; }
private:
void clear();
public:
BMINFO* pInfo;
char* pBits;
HBITMAP m_Bitmap;
};
// BlockBitmap.cpp
BlockBitmap::BlockBitmap(void)
{
pInfo = NULL;
pBits = NULL;
m_Bitmap = NULL;
}
BlockBitmap::~BlockBitmap(void)
{
clear();
}
void BlockBitmap::clear()
{
if ( pInfo != NULL )
delete pInfo;
if ( pBits != NULL )
delete[] pBits;
if ( m_Bitmap != NULL )
DeleteObject(m_Bitmap);
}
bool BlockBitmap::setBitmap(BMINFO* pbmInfo, char* pbmBits)
{
if(pbmInfo->bmiHeader.biBitCount != 8){
WsMessage::WsMessageBox(NULL, "Currently supports only 8bits paletts !", "Bitmap set error", MB_ICONERROR | MB_OK);
return false;
}
if(pInfo != 0)
delete pInfo;
if(pBits != 0)
delete pBits;
pInfo = new BMINFO();
int szBts = pbmInfo->bmiHeader.biSizeImage;
pBits = new char[szBts];
memcpy(pInfo, pbmInfo, sizeof(BMINFO));
memcpy(pBits, pbmBits, szBts);
m_Bitmap = CreateDIBitmap(NULL, &pInfo->bmiHeader, CBM_INIT, pBits,
(BITMAPINFO *)&pInfo->bmiHeader, DIB_RGB_COLORS);
WLASSERT( m_Bitmap != NULL );
return true;
}
bool BlockBitmap::setBitmap(const char* pbuff)
{
BMINFO* pf = (BMINFO*)pbuff;
char* pb = (char*)pf + (int)sizeof(BMINFO);
return setBitmap(pf, pb);
}
// ... cpp
void getBlockHBitmap( const AcDbObjectId btrId, BlockBitmap* hBmp)
{
AcDbDatabase* pDb = ...;
AcAxDocLock docLock(pDb);
AcDbObject* pObj = NULL;
AcDbBlockTableRecord* pBtr = NULL;
if (acdbOpenAcDbObject( pObj, btrId, AcDb::kForRead) == Acad::eOk)
{
pBtr = AcDbBlockTableRecord::cast(pObj);
WLASSERT( pBtr != NULL );
if ( pBtr->hasPreviewIcon() )
{
AcArray<Adesk::UInt8> previewIcon;
pBtr->getPreviewIcon(previewIcon);
WLASSERT( previewIcon.length() == 2088 );
BYTE imgPreview[2088];
memcpy(imgPreview, previewIcon.asArrayPtr(), previewIcon.length());
hBmp->setBitmap(imgPreview);
}
}
pObj->close();
}