winprog's isn't working for me
it works but whenever I try to put it in another project it bombs...and is there a way to have a transparent bitmap but loaded from a file instead of from a resource file?
Im really lookng to just make this a class for easy use.
Here is a real basic tutorial I made awhile back. There is a html file in there that is the acutal tutorial. I am not sure if it is the complete one anymore. The real one was on my site before my ISP destroyed it. I hope this helps
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com
Also here is some code from an old project of mine that has a transparent bitmap. You can probably figure it out
Code:
/*###########################################################################################*/
/*
======================================================================================
Name: DrawTransparentBitmap
Return: None
In: HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF cTransparentColor
Notes: hdc Of The Device To Paint To, hBitmap Is The Bitmap To Be Transparent, XandYShort
Is The X and Y To Paint On The Device, Color Is The Color To Make Transparent
======================================================================================
*/
void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xPaint, short yPaint, short xStart, short xEnd, COLORREF cTransparentColor)
{
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
HDC hdcMem = CreateCompatibleDC(0);
HBITMAP hbmColour,
hbmMask;
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
//Get The Orginal Bitmap
hbmColour = hBitmap;
//Get The Mask, Make All Perfect Red Tansparent
hbmMask = CreateBitmapMask(hbmColour, cTransparentColor,xStart, xEnd);
if(xStart == -1)
{
//Get The Passed In Bitmap Info
BITMAP bm;
GetObject(hbmColour, sizeof(BITMAP), &bm);
//BitBlt The Mask Image To The Screen
SelectObject(hdcMem, hbmMask);
BitBlt(hdc, xPaint, yPaint, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCAND);
//BitBlt The Orginal Over The Mask
SelectObject(hdcMem, hbmColour);
BitBlt(hdc, xPaint, yPaint, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCPAINT);
}
else
{
//BitBlt The Mask Image To The Screen
SelectObject(hdcMem, hbmMask);
BitBlt(hdc, xPaint, yPaint, xEnd, 45, hdcMem, xStart, 0, SRCAND);
//BitBlt The Orginal Over The Mask
SelectObject(hdcMem, hbmColour);
BitBlt(hdc, xPaint, yPaint, xEnd, 45, hdcMem, xStart, 0, SRCPAINT);
}
//Clean Up
DeleteDC(hdcMem);
DeleteObject(SelectObject(hdcMem, hbmMask));
DeleteObject(SelectObject(hdcMem, hbmColour));
}
/*###########################################################################################*/
/*
======================================================================================
Name: CreateBitmapMask
Return: HBITMAP
In: HBITMAP hbmColour, COLORREF crTransparent
Notes: Returns The Mask For The Previous Function
Function Was Not Created By Me
======================================================================================
*/
HBITMAP CreateBitmapMask(HBITMAP hbmColour, COLORREF crTransparent,short xStart, short xEnd)
{
HDC hdcMem, hdcMem2;
HBITMAP hbmMask;
BITMAP bm;
/*
Create mask bitmap.
*/
GetObject(hbmColour, sizeof(BITMAP), &bm);
hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);
hdcMem = CreateCompatibleDC(0);
hdcMem2 = CreateCompatibleDC(0);
SelectObject(hdcMem, hbmColour);
SelectObject(hdcMem2, hbmMask);
/*
Set the background colour of the colour image to the colour
you want to be transparent.
*/
SetBkColor(hdcMem, crTransparent);
/*
Copy the bits from the colour image to the B+W mask... everything
with the background colour ends up white while everythig else ends up
black...Just what we wanted.
*/
BitBlt(hdcMem2, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
/*
Take our new mask and use it to turn the transparent colour in our
original colour image to black so the transparency effect will
work right.
*/
BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0, SRCINVERT);
//Clean up.
DeleteDC(hdcMem);
DeleteDC(hdcMem2);
return hbmMask;
}
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com