Click here to Skip to main content
15,919,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i'm trying build Regions from a Bitmaps:
C++
HRGN CreateRegionFromBitmap(HBITMAP hBitmap, COLORREF transparentColor)
{
	HRGN hRgn = NULL;
	HRGN hRgn1 = NULL;

	// Check for valid bitmap handle
	if ( hBitmap != NULL )
	{
		// Get bitmap object information
		BITMAP bitmap;
		GetObject(hBitmap, sizeof(BITMAP), &bitmap);
		DWORD dwSize = bitmap.bmHeight * bitmap.bmWidthBytes;
		int bitsPixel = bitmap.bmBitsPixel / 8;

		// Check bitmap color depth (only 24 or 32 bits per pixel allowed)
		if ( ( bitsPixel == 3 ) || ( bitsPixel == 4 ) )
		{
			// Get bitmap bits
			unsigned char* pBits = new unsigned char[dwSize];
			GetBitmapBits(hBitmap, dwSize, pBits);

			// Create region from bitmap
			unsigned char red, green, blue;
			for ( int y=0; y<bitmap.bmHeight; y++ )
			{
				for ( int x=0; x<bitmap.bmWidth; x++ )
				{
					// Get pixel color
					blue = pBits[y*bitmap.bmWidthBytes + bitsPixel*x];
					green = pBits[y*bitmap.bmWidthBytes + bitsPixel*x+1];
					red = pBits[y*bitmap.bmWidthBytes + bitsPixel*x+2];

					// Check transparent color
					if(x==1 && y==1 && RGB(red,green,blue)== transparentColor)
                        SetWindowText(ActivatedForm,"match transparent");
					if ( RGB(red,green,blue) != transparentColor )
					{
						// Combine regions
						if ( hRgn == NULL )
							hRgn = CreateRectRgn(x, y, x+1, y+1);
						else
						{
							// Delete temporary region
							if ( hRgn1 != NULL )
								DeleteObject(hRgn1);

							// Create temporary region
							hRgn1 = CreateRectRgn(x, y, x+1, y+1);

							// Combine regions
							CombineRgn(hRgn, hRgn, hRgn1, RGN_OR);
						}
					}
				}
			}

			// Free bitmap bits
			delete pBits;
		}
	}

	// Delete temporary region
	if ( hRgn1 != NULL )
		DeleteObject(hRgn1);

	return hRgn;
}

heres how i use it on WM_PAINT:
C++
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?
Posted

1 solution

I am not sure that I understand your question but the following article may help you: http://www.flipcode.com/archives/Win32_Window_Skinning.shtml[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900