Archived

This topic is now archived and is closed to further replies.

What's wrong with this???

This topic is 5239 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

These are the two functions I use to make a bitmap mask and draw the bitmap with transparency to the window, but it doesn''t work for some reason, part of the code is from a tutorial on Win32 API and some is from my own reworking of it. On the MSDN website there is a function called TransparentBlt, but I can''t get it to work and I don''t want to keep messing with it, but there was a link from that page to show how to do transparency with BitBlt instead, like the function I have, but the link is dead. So now I have nowhere else to turn for adivce on why my functions don''t work, when I try to display a red ball bitmap that has a white background it draws the bitmap like the original, but with the white area now black. The code is below, Plz HELP!!! HBITMAP CreateBitmapMask( HBITMAP hbmBitmap, COLORREF crTransparent ) { HDC hdcMem, hdcMem2; HBITMAP hbmMask; BITMAP bitmap; GetObject(hbmBitmap, sizeof(BITMAP), &bitmap); hbmMask = CreateBitmap(bitmap.bmWidth, bitmap.bmHeight, 1, 1, NULL); hdcMem = CreateCompatibleDC(0); hdcMem2 = CreateCompatibleDC(0); SelectObject(hdcMem, hbmBitmap); SelectObject(hdcMem2, hbmMask); SetBkColor(hdcMem, crTransparent); BitBlt(hdcMem2, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY); BitBlt(hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem2, 0, 0, SRCINVERT); DeleteDC(hdcMem); DeleteDC(hdcMem2); return hbmMask; } void DrawBitmap( HDC hdc, HBITMAP hbmBitmap, COLORREF crTransparent, int x, int y ) { BITMAP bitmap; HBITMAP hbmMask = CreateBitmapMask(hbmBitmap, crTransparent); HDC hdcMem = CreateCompatibleDC(hdc); HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hbmMask); GetObject(hbmBitmap, sizeof(bitmap), &bitmap); BitBlt(hdc, x, y, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCAND); SelectObject(hdcMem, hbmBitmap); BitBlt(hdc, x, y, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCPAINT); SelectObject(hdcMem, hbmOld); DeleteDC(hdcMem); } It is probably something stupid I over looked or I might be doing t his totally wrong, either way I could use some help. THX, JAP

Share this post


Link to post
Share on other sites
Well, Im only just learning this stuff myself so take it with a grain of salt but why break out the CreateBitmapMask as a separate function? Just put everything in the Draw.

I suspect the reason why its not working the way you have it is because hbmMask never gets updated, all you're doing is blitting to the HDCs and throwing them away at the end.

Im at work so I can't post my transparent blitting function up here. If you don't get an answer I'll post it tonight.

[edited by - strewth on August 13, 2003 11:32:36 PM]

Share this post


Link to post
Share on other sites