Link to home
Start Free TrialLog in
Avatar of yossikally
yossikally

asked on

Looking for a transparent-background-picture-control for MFC

All of the solutions I have found so far are image based - pass them a bitmap handle, trasparent color and a DC and it's drawn OK.  But I already put my images on the dialog with the resource editor, now I want them to be drawn without transparent color.

I guess I am looking for a CStatic derived class that handles tranparency. Couldn't find any.
Thanks for your help.
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

There is no such CStatic. And, I'm afraid, you have to accept it as an answer.
CStatic is a window. It is possible to make this window transparent and so, the image inside will be transparent too.

It is much easier just to draw the image you need directly on your dialog (or whatever you use).
With this approach you have more freedom and may use many options beginning from the trivial TransparentBlt, ATL CImage, Image in GDI+, etc. I'll be glad to help you if you will choose this way.

I do not know about new things added to MFC for Windows 7 GUI. So I can be wrong.

Avatar of AndyAinscow
>now I want them to be drawn without transparent color.

Resource editor, add a new picture control.  Properties - set 'type' to bitmap, 'transparent' to false, 'image' to the ID of the bitmap.
Result - bitmap displays on dialog that is not transparent.
Avatar of yossikally
yossikally

ASKER

I other words, if you use picture controls in the resource editor, there is no way for them to be drawn with transparent background?  I find it hard to accept.

Especially after I found a nice class in CodeProject defined as
class CImageButton : public CButton
that does exactlry that on a CButton.
So why not on a CStatic?  It's only easier.
AndyAinscow: You got the opposite idea :( (my fault I guess)
I want it to be drawn with transparency: to be explicit - my drawing is shaped as an ellipse, surrounded with red background.  I don't want the red to show.
Try the way AndyAinscow proposed for you.
Ok. Of course there is such control. I have my own too (but it is not a window). I thought you are asking about a standard MFC control. I do not know if there is one like you need in the MFC Feature Pack.
Well you diid specifically ask for non-transparent....


try setting transparent to true - I think the top left pixel in the bitmap is used as the transparency colour.
pgnatyuk:  Thanks.  That's what I meant.  
Can someone refer me to a link to such a control in the public domain
Thanks
AndyAinscow: setting 'Transparent' to true doesn't work (see pic)  Am I doing something wrong?
kuku.JPG
If you want I will show you how to draw an image in you dialog without any CStatic. It is really simple.
1. Add a function that will receive CDC* and CRect as the input parameters.
2. Call this function from OnPaint.
That's all.
Thanks.  That I know and there are lots of samples.  

Still, I already have my image on the dialog by way of the resource editor.  So how do I make those with transparent background?
Hmmm - maybe I remembered incorrectly.  I'll see if I can find what determines the transparancy.
Found a way.
Don't use bitmaps - use icons instead.
Make a new icon.
Set a default size (new image menu point)
copy / paste your current bitmap image in there.
delete any other image sizes in the icon (change to each image via menu - delete)
in the picture control - change it to icon, set the icon as I said previously.  Allow the real image size option.

Should now be a transparent image as you wanted.
I didn't quite understand your instructions but I'm afraid it won't work because my bitmap is 24 bit color.
Also - isn't an icon limited to a certain size? Didn't understand how to set it's size.

Raised to 500 points.
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK. I thank you for your effort and I am splitting the points between you two.
The B is because I did not get a solution along the lines of my intiial question.

Still - thanks for the effort.