Using a transparent bitmap with CBitmapButton.

I am using the CBitmapButton class to create buttons with a different look than the standard MFC controls.

I don't want to be limited to only rectangular shaped buttons so I tried using a bitmap with transparent sections to display a rectangle with slightly rounded edges. When the bitmap is drawn on the dialog, the transparent sections show up as a white color and do not let the background image show through.

Does anyone know how to create non-rectangular bitmap buttons? Can this be done using the CBitmapButton class? Please include some sample code with your answer. Thanks.

cdgoughAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
Look at the Non-Rectangular buttons section of the following page.

http://www.codeguru.com/buttonctrl/index.shtml
0
cdgoughAuthor Commented:
Thanks, but there are a couple problems with the proposed answer:

All of the samples on Code Guru discussing non-rectangular buttons create these buttons by building regions that can be defined mathematically -- circles, stretched circles, triangles, etc. or though special CRgn functions like CreateEllipticalRegion( ... ). They don't allow for a blob or other shape that cannot be defined by an equation or the union and intersection of other primitive shapes.

The samples you pointed too are very cool, but don't describe what I'm looking for.

For example, I wouldn't mind just using a standard rectangular bitmapped button -- I just want the background of the dialog to show through certain portions of the bitmap (i.e. the button). So In a perfect world I would be able to use the standard CBitmapButton class, but somehow I would be able to define certain areas on my bitmap resource to be "see-through".

Does this help?
0
chensuCommented:
In this case, I would simply draw the bitmap transparently and handle the mouse messages rather than use CButton or CBitmapButton.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Gandalf32Commented:
On the same site (www.codeguru.developer.com) there is a section on transparent bitmaps. Just define your button windows as transparent, and draw a transparent bitmap on it.
0
luisrCommented:
Try the CButtonST class. It allows for transparent buttons. You can download it from the following address:

http://members.tripod.com/~SoftechSoftware/index.html

I hope it is what you are looking for.
0
PIGCommented:
You must catch WM_ERASEBKGND message for Your button and return TRUE.
0
cdgoughAuthor Commented:
I'm going to need a more information than that for 200 points.

Can you please describe the entire process? What other functions do I need to override? Do I need to do anything special when creating the bitmap? etc, etc.

Thanks.
0
luisrCommented:
Try CButtonST!! it's just what you need!
0
cdgoughAuthor Commented:
I looked at CButtonST and it looks like it supports only icons, not bitmaps. I don't want to be restricted to a 32x32 or 64x64 sized image on my buttons. Did you get the CButtonST class to work with different sized bitmap resources?
0
luisrCommented:
You're right, CButtonST only works with icons, but I looked at the source code and it could be easily modified to add support for bitmaps. I have a little routine somewhere that draws a bitmap on a device context, taking one color as transparent. With it you could easily adapt CButtonST to use bitmaps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cdgoughAuthor Commented:
Please show how/where to make these changes, and I will award you the points.

Thanks.
0
ShivaliCommented:
Hello Luisr;
I would like to know more on this specially about loading a bitmap on the button,and is there any way i can save the task of saving the background with each button as the CButtonST class suggests.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.