views:

329

answers:

3

I have a Window (win32 API) Application in visual c++. I am not using MFC. I have to create a round/circular button with bitmap image. My application have a skined view. Can any one help me out in achieving this task. Thanks in advance.

A: 

You can google to find techniques for BitBlting images using memory DC and various ROP2 settings to achieve a masking effect. Your round image that represents the button would use a specific color to represent transparency. I don't have the specific code at hand but it is non-trivial.

AlanKley
+1  A: 

Buttons are windows. You can create a button with the CreateWindow or CreateWindowEx call:

-http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx

When you create your button window ensure that you pass the BS_OWNDERDRAW style:

-http://msdn.microsoft.com/en-us/library/bb775951(VS.85).aspx

That will tell the button to send WM_DRAWITEM messages to your buttons' WNDPROC:

-http://msdn.microsoft.com/en-us/library/bb775923(v=VS.85).aspx

In your buttons' WNDPROC you would handle the WM_DRAWITEM message and paint your button according to the information in the DRAWITEMSTRUCT received as a pointer in lParam.

To render a bitmap as anything but rectangular you will need to provide a 1-bit bitmask bitmap the same size as the bitmap you wish to render for your button. The bitmask has bits set where you want the pixels in your button bitmap to be set on the screen. The pixels in your button bitmap that do not display need to be black. Bitblt your bitmask bitmap to the screen with the AND operator then OR your button bitmap. Of course you will need to account for the various button states (normally a push button is only two states.)

I may have mixed the black/white or set/unset bits in the explanation above, but the AND / OR bitwise (SRCAND/SRCPAINT) Raster Operations are the correct operations for what you are trying to acheive.

-http://msdn.microsoft.com/en-us/library/aa930997.aspx

Hope that helps.

Installer
A: 

The key api call you need to know is SetWindowRgn. This is what you call to tell windows that the the window is not rectangular but an irregular region. If you google around for that, you will find lots of sample code.

One promising example is this project. It does depend on MFC, but you can use it to learn what you need to call in what order to get the desired effect.

jdv