Transparent Icons vs. Subclassed CBitmap?

Transparent Icons vs. Subclassed CBitmap?

Post by Dan McCart » Fri, 28 Jan 2005 11:22:50


I'm using MFC for CE on a graphics-intense app, and I need to draw lots
of little symbols to the screen. I have a lot of symbols that are
64x64, and a lot at 128x128. (I have lots more that don't care about 2
or its powers, but I won't get into that just yet.) I'm currently
creating an array of CStatic controls at run-time and this allows me to
with these bitmaps very nicely.

But I need to handle transparency, and I was about to extend CBitmap to
do that, when I realized that icon resources have built-in
transparency. I downloaded Microangelo and came up with a nice
64x64x256 icon that I can get to paint on the screen.

However, MFC doesn't have a CIcon class to make handling them easier,
and I'm afraid that creating lots of non-standard icons will result in
headaches down the road. For example, I've already found that the eVC
dialog designer manually sets the icon size to 32x32 and WinCE
dutifully draws it that way. Only by grabbing a handle to it at
run-time and calling MoveWindow can I can show it in its 64-pixel
glory.

Does anyone have any thoughts as to whether I should take the time to
develop transparent bitmaps? Or should I take the time to work around
hassles that I expect I'll have with non-traditional icon resources?
Thanks in advance for any ideas or suggestions.

Thanks,
Dan.
 
 
 

Transparent Icons vs. Subclassed CBitmap?

Post by Marius Pri » Fri, 28 Jan 2005 22:49:33

Hi,


Look at the "TransparentImage" API. Note that this API had a memory leak on
versions of Windows CE less than 3.0 but it looks like it was fixed in 3.0+.
If this API is not available for some reason, you can easily create your own
that handles transparency by successive BitBlt operations. You just create a
1 bit per pixel bitmap, select it into a compatible DC to the dc of the
screen you want to display it on (say transDC), then you create another dc
(say memDC) that is going to be the target of all combined colors [to obtain
transparency.] This DC will be a "clone" of the display DC.. (just to avoid
flickering... ) and so, suppose you have a DC for the bitmap to be stored
in.."bitmapDC" (which is also a DC same as the display DC..) then all you do
is: fill it w/ the color to be transparent in the bitmap, set bkmode of it
to "TRANSPARENT", set bkcolor to that same color, draw the bitmap in it;
copy from bitmapDC to "transDC" by "SRCCOPY"; copy from bitmapDC to memDC w/
"SRCINVERT", then copy from transDC to memDC w/ "SRCAND" and lastly copy
from bitmapDC to memDC w/ "SRCINVERT". Now you have transparency in memDC
and you can copy it w/ "SRCCOPY" to the actual DC display. This is the "main
idea" .. I may have missed a few things since I'm writing this w/o looking
at any code but if you want to go this path and you have problems let me
know and I will provide a better step-by-step procedure.

Marius

 
 
 

Transparent Icons vs. Subclassed CBitmap?

Post by Dan McCart » Wed, 02 Feb 2005 04:40:04

TransparentImage() works wonderfully. If I run into speed issues I'll
go with your other idea. BTW, and I haven't tested it, I did see
another post that said that blitting using MAKEROP4(MERGEPAINT,
SRCCOPY) as the last paramenter would work for transparent imagess,
too. (?)

Thanks agian,
Dan.