Hi guys

i?m trying to make a replacement for alphablend and transparentblt for usage in win95, win98 OSes.

I found this article explaining the technique.

http://www.ddj.com/dept/windows/184416353?pgno=21

But.. it simply does not works :(

The replacements are necessary, because for what i heard so far, the blending functions have memory leaks in all windows versions.

Note: The AlphaBlend function inside msimg32 dll is exactly the same one as GdiAlphaBlend from gdi32.dll (except for the error codes that seems to be inside the msimg32.dll), but someone knows if GdiAlphaBlend  works under win95, 98 and NT4 ?


Best Regards,

Guga
Posted on 2007-02-25 17:29:42 by Beyond2000!
I remember answering this question here. Please use the search function. Additionally, Microsoft explains it very decently and provides working C source code as well:
bool TransparentBltU(
HDC dcDest, // handle to Dest DC
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
int nWidthDest, // width of destination rectangle
int nHeightDest, // height of destination rectangle
HDC dcSrc, // handle to source DC
int nXOriginSrc, // x-coord of source upper-left corner
int nYOriginSrc, // y-coord of source upper-left corner
int nWidthSrc, // width of source rectangle
int nHeightSrc, // height of source rectangle
UINT crTransparent // color to make transparent
)
{
if (nWidthDest < 1) return false;
if (nWidthSrc < 1) return false;
if (nHeightDest < 1) return false;
if (nHeightSrc < 1) return false;

HDC dc = CreateCompatibleDC(NULL);
HBITMAP bitmap = CreateBitmap(nWidthSrc, nHeightSrc, 1,
GetDeviceCaps(dc, BITSPIXEL), NULL);

if (bitmap == NULL)
return false;

HBITMAP oldBitmap = (HBITMAP)SelectObject(dc, bitmap);

if (!BitBlt(dc, 0, 0, nWidthSrc, nHeightSrc, dcSrc,
nXOriginSrc, nYOriginSrc, SRCCOPY))
return false;

HDC maskDC = CreateCompatibleDC(NULL);
HBITMAP maskBitmap = CreateBitmap(nWidthSrc,
nHeightSrc, 1, 1, NULL);

if (maskBitmap == NULL)
return false;

HBITMAP oldMask = (HBITMAP)SelectObject(maskDC,
maskBitmap);

SetBkColor(maskDC, RGB(0,0,0));
SetTextColor(maskDC, RGB(255,255,255));
if (!BitBlt(maskDC, 0,0,nWidthSrc,nHeightSrc,NULL,
0,0,BLACKNESS))
return false;

SetBkColor(dc, crTransparent);
BitBlt(maskDC, 0,0,nWidthSrc,nHeightSrc,dc,0,0,SRCINVERT);

SetBkColor(dc, RGB(0,0,0));
SetTextColor(dc, RGB(255,255,255));
BitBlt(dc, 0,0,nWidthSrc,nHeightSrc,maskDC,0,0,SRCAND);

HDC newMaskDC = CreateCompatibleDC(NULL);
HBITMAP newMask;
newMask = CreateBitmap(nWidthDest, nHeightDest, 1,
GetDeviceCaps(newMaskDC, BITSPIXEL), NULL);

if (newMask == NULL)
{
SelectObject(dc, oldBitmap);
DeleteDC(dc);
SelectObject(maskDC, oldMask);
DeleteDC(maskDC);
DeleteDC(newMaskDC);
return false;
}

SetStretchBltMode(newMaskDC, COLORONCOLOR);
HBITMAP oldNewMask = (HBITMAP) SelectObject(newMaskDC,
newMask);
StretchBlt(newMaskDC, 0, 0, nWidthDest, nHeightDest,
maskDC, 0, 0, nWidthSrc, nHeightSrc, SRCCOPY);

SelectObject(maskDC, oldMask);
DeleteDC(maskDC);

HDC newImageDC = CreateCompatibleDC(NULL);
HBITMAP newImage = CreateBitmap(nWidthDest, nHeightDest,
1, GetDeviceCaps(newMaskDC, BITSPIXEL), NULL);

if (newImage == NULL)
{
SelectObject(dc, oldBitmap);
DeleteDC(dc);
DeleteDC(newMaskDC);
return false;
}

HBITMAP oldNewImage = (HBITMAP)SelectObject(newImageDC,
newImage);
StretchBlt(newImageDC, 0, 0, nWidthDest, nHeightDest,
dc, 0, 0, nWidthSrc, nHeightSrc, SRCCOPY);

SelectObject(dc, oldBitmap);
DeleteDC(dc);

BitBlt( dcDest, nXOriginDest, nYOriginDest, nWidthDest,
nHeightDest, newMaskDC, 0, 0, SRCAND);

BitBlt( dcDest, nXOriginDest, nYOriginDest, nWidthDest,
nHeightDest, newImageDC, 0, 0, SRCPAINT);

newImage = (HBITMAP)SelectObject(newImageDC, oldNewImage);
DeleteObject(newImage) ;
DeleteDC(newImageDC);
newMask = (HBITMAP)SelectObject(newMaskDC, oldNewMask);
DeleteObject(newMask) ;
DeleteDC(newMaskDC);
DeleteDC(dc) ;
DeleteObject(bitmap) ;

return true;
}


Know that the bug is said to occur only on Win9x, so first check which OS your app runs on.
Posted on 2007-02-26 11:52:00 by ti_mo_n
Why not simply use sDraw?
Posted on 2007-02-26 12:25:04 by Ultrano
sDraw rocks  :thumbsup:

I hope you keep updating and releasing to the public Ultrano
Posted on 2007-02-26 12:46:11 by mango
Hi Ultrano

what is SDraw ?

Is it a library of yours ? If it is, do u have any link ?

Best Regards,

Guga
Posted on 2007-02-28 13:35:53 by Beyond2000!
Yes, it's here: http://www.asmcommunity.net/board/index.php?topic=24967.0

mango: I hadn't planned any updates, but yesterday I finally decided to finally solve/create some graphical "algo" that's been keeping me in awe for years - and in the process sDraw obtained drawing of 1) Bresenham lines, 2) B-splines , and both drawable via custom "shaders"  :

(the cables are animated like rubber-rope)
I'll also be adding some text-drawing features, and easy GDI interworking. Though, don't hold your breath - I was just given some important projects to work on, and it'll be days before I can come back to it ^^".
Posted on 2007-02-28 15:51:09 by Ultrano
Wow  :shock: :shock: :shock:

Impressive work, ultrano.

Congratulations


Best Regards,

Guga
Posted on 2007-03-05 00:29:43 by Beyond2000!
Thanks ^_^
Posted on 2007-03-05 02:32:15 by Ultrano