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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
luisrConnect With a Mentor Commented:
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
 
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
chensuCommented:
In this case, I would simply draw the bitmap transparently and handle the mouse messages rather than use CButton or CBitmapButton.
0
 
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
 
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
All Courses

From novice to tech pro — start learning today.