Introduction
Needless to say that a bitmap is the gateway between different raster image formats and GDI image representation.
Device Independent Bitmaps or DIBs are important objects that allow us to save, load and draw images without thinking
of display mode in device context - independent way. OS will do its best to output them as close to original, as
it is able, because DIBs contain all necessary color usage, color depth, and image resolution information. There
are many, or better say, numerous classes that support DIB operations through wrapping Windows API functions. This
MFC extension DLL contains such class and a bit more to make bitmap usage easier and more flexible.
Classes included
All class declarations are included in the bmpext.h header.
Device dependent bitmap (DDB) extension class CDDBDrawEx:
This class is intended for on-stack allocation and usage within the single scope, as it has no default constructor
and no "real" data members, only pointers to externally defined ones.
It exposes public methods as follows:
CDDBDrawEx(CDC* pDC, CBitmap* pbmSrc, CBitmap* pbmBack = NULL);
void Fill(CRect& rDest);
void Draw(CRect& rDest, CPoint& pntSrc);
void DrawTransparent(CRect& rDest, CPoint& pntSrc, COLORREF crMask);
HRGN MakeRgn(COLORREF cTransparentColor = 0, COLORREF cTolerance = 0x101010);
DIBitmap encapsulation class CDib:
This class and the Frankenstein monster have much in common :) Part of its code was taken from samples shipped
with MFC 4.0 book, partially from CodeGuru and other sources. I have modified it, put it together, and said "It's
alive... ALIVE!" :)
It exposes public methods as follows:
<CODE>
CDib();
DWORD Width();
DWORD Height();
WORD NumColors( BITMAPINFOHEADER& bmiHeader );
BOOL IsValid();
void Invalidate();
BOOL Draw(CDC*, CRect& rectDC, CRect& rectDIB);
void SetPixel( int iX, int iY, RGBQUAD& rgbPixel );
RGBQUAD GetPixel(int iX, int iY);
DWORD Save(CFile& file);
DWORD Read(CFile& file, BOOL bFromResource = FALSE );
DWORD ReadFromResource(UINT nResID);
HBITMAP CreateDDBitmap(CDC* pDC);
HBITMAP CreateDDBitmap( HDC hDC );
BOOL Compress(CDC* pDC, BOOL bCompress );
CDib& operator = (CDib& dib);
Extension Classes Usage
CDDBDrawEx class usage:
<CODE>{
....
....
CDDBDrawEx ddbDrawEx(pDC, bmImg);
ddbDrawEx.DrawTransparent(rDest, CPoint(0), crImgMask );
ddbDrawEx.Fill( rDest )
}
{
....
CDDBDrawEx ddbDrawEx(NULL, &m_bmSkin );
return ddbDrawEx.MakeRgn( m_crTransparent, m_crTolerance );
}
CDib class usage:
<CODE>CDib dibTemp;
CDC* pDC = CDC::FromHandle( ::GetDC( NULL ) );
....
dibTemp.ReadFromResource( nResID );
....
}
Demo project implementing these extensions also includes class template for customizing dialog frame. I'm going
to describe this template in detailed review which I plan to publish in a week. It will cover the window frames
customization technique and will be supplemented with couple of helper template class. That's all so far, but I
will supply several useful control and animation class libs packaged as MFC extension DLL in the nearest future.
Additions, corrections and suggestions are always welcomed, as I often haven't enough time to optimize my source
or make it more elegant. Mail me at: gromov@eti.co.ru.