1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
const int LastPixel=-1;
const int FirstPixel=-2;
void DrawHBITMAPtoHDC(HBITMAP hBitmap, HDC hdc, int PosX=0, int PosY=0, COLORREF backcolor=-1)
{
BITMAP bm;
HDC MemDCExercising = CreateCompatibleDC(hdc);
HBITMAP oldbitmap =(HBITMAP) SelectObject(MemDCExercising, hBitmap);
GetObject(hBitmap,sizeof(bm),&bm);
if(backcolor==LastPixel)
TransparentBlt(hdc, PosX, PosY, bm.bmWidth , bm.bmHeight, MemDCExercising, 0, 0,bm.bmWidth , bm.bmHeight,GetPixel(MemDCExercising,bm.bmWidth-1,bm.bmHeight-1));
else if(backcolor==FirstPixel)
TransparentBlt(hdc, PosX, PosY, bm.bmWidth , bm.bmHeight, MemDCExercising, 0, 0,bm.bmWidth , bm.bmHeight,GetPixel(MemDCExercising,0,0));
else
TransparentBlt(hdc, PosX, PosY, bm.bmWidth , bm.bmHeight, MemDCExercising, 0, 0,bm.bmWidth , bm.bmHeight,backcolor);
SelectObject(MemDCExercising,oldbitmap);
DeleteDC(MemDCExercising);
DeleteObject(hBitmap);
}
//...............................
BitmapDC& operator= (const BitmapDC &bitmapsource)
{
if (this == &bitmapsource) // Same object?
return *this;
destroy();
init(bitmapsource.intwidth, bitmapsource.intheight);
BitBlt(bitmapsource, 0, 0, intwidth, intheight, hdcbitmap, 0, 0, SRCCOPY);
return *this;
}
BitmapDC& operator= (const HBITMAP &bitmapsource)
{
destroy();
BITMAP bm;
GetObject(bitmapsource,sizeof(bm),&bm);
init(bm.bmWidth, bm.bmHeight);
DrawHBITMAPtoHDC(bitmapsource,hdcbitmap);
return *this;
}
|