Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2009-12-29
18
Medium Priority
?
2,308 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:yossikally
  • 8
  • 5
  • 5
18 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26138421
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.

0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 26138443
>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.
0
 

Author Comment

by:yossikally
ID: 26138472
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:yossikally
ID: 26138500
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.
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26138507
Try the way AndyAinscow proposed for you.
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26138523
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.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 26138560
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.
0
 

Author Comment

by:yossikally
ID: 26138568
pgnatyuk:  Thanks.  That's what I meant.  
Can someone refer me to a link to such a control in the public domain
Thanks
0
 

Author Comment

by:yossikally
ID: 26138606
AndyAinscow: setting 'Transparent' to true doesn't work (see pic)  Am I doing something wrong?
kuku.JPG
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26138641
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.
0
 

Author Comment

by:yossikally
ID: 26138785
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?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 26138932
Hmmm - maybe I remembered incorrectly.  I'll see if I can find what determines the transparancy.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 26140116
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.
0
 

Author Comment

by:yossikally
ID: 26140330
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.
0
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 750 total points
ID: 26140631
So what is the question?

You asked if a "transparent" CStatic exists? I've answered - no. Not in MFC.
Because such control is a window. It is possible to make a window shape exactly as an image drawn in it. But it looks ugly.

Any window has a brush that cleans the background. If this brush will be NULL, the window will be transparent. But you will have a problem with the parent window. It is also a way, but we need to know more about the entire task to recommend something more specific.

I've said, in such case, it is better to draw the image in the dialog. If you want it can be a "control" - it will have the same methods as its MFC brother. If you have few images like that, it makes sense to get complicated and develop this control.

I'm going to leave this thread exactly at this point.

Happy New Year!
0
 
LVL 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 750 total points
ID: 26143985
If an icon isn't suitable then I don't think I can help further either.  (Icons can have custom sizes - look at the menu options in the resource editor and look at my comment).
I agree with pgnatyuk - if you have functional code already it should be trivial to write your own class to do something more or less what you want.
0
 

Author Comment

by:yossikally
ID: 26144012
OK. I thank you for your effort and I am splitting the points between you two.
0
 

Author Closing Comment

by:yossikally
ID: 31670793
The B is because I did not get a solution along the lines of my intiial question.

Still - thanks for the effort.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question