i'm trying build Regions from a Bitmaps:
HRGN CreateRegionFromBitmap(HBITMAP hBitmap, COLORREF transparentColor)
{
HRGN hRgn = NULL;
HRGN hRgn1 = NULL;
if ( hBitmap != NULL )
{
BITMAP bitmap;
GetObject(hBitmap, sizeof(BITMAP), &bitmap);
DWORD dwSize = bitmap.bmHeight * bitmap.bmWidthBytes;
int bitsPixel = bitmap.bmBitsPixel / 8;
if ( ( bitsPixel == 3 ) || ( bitsPixel == 4 ) )
{
unsigned char* pBits = new unsigned char[dwSize];
GetBitmapBits(hBitmap, dwSize, pBits);
unsigned char red, green, blue;
for ( int y=0; y<bitmap.bmHeight; y++ )
{
for ( int x=0; x<bitmap.bmWidth; x++ )
{
blue = pBits[y*bitmap.bmWidthBytes + bitsPixel*x];
green = pBits[y*bitmap.bmWidthBytes + bitsPixel*x+1];
red = pBits[y*bitmap.bmWidthBytes + bitsPixel*x+2];
if(x==1 && y==1 && RGB(red,green,blue)== transparentColor)
SetWindowText(ActivatedForm,"match transparent");
if ( RGB(red,green,blue) != transparentColor )
{
if ( hRgn == NULL )
hRgn = CreateRectRgn(x, y, x+1, y+1);
else
{
if ( hRgn1 != NULL )
DeleteObject(hRgn1);
hRgn1 = CreateRectRgn(x, y, x+1, y+1);
CombineRgn(hRgn, hRgn, hRgn1, RGN_OR);
}
}
}
}
delete pBits;
}
}
if ( hRgn1 != NULL )
DeleteObject(hRgn1);
return hRgn;
}
heres how i use it on WM_PAINT:
if(inst->blnTransparent==true)
{
SetWindowRgn( inst->hwnd,NULL,TRUE);
BitBlt(test.hdc,0,0,test.rcPaint.right,test.rcPaint.bottom,imglabel,0,0,SRCCOPY);
SetWindowRgn( inst->hwnd, CreateRegionFromBitmap(imglabel,inst->clrBackColor),TRUE);
}
imglable: is my image class that can return HBITMAP.
test: is the PAINTSTRUCT object.
inst: is my control object pointer(my controls are subclassed).
the control isn't shaped and i don't understand why :(
can anyone advice me?