Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - CXTPButton with rounded corners
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPButton with rounded corners

 Post Reply Post Reply
Tapan View Drop Down

Joined: 25 May 2006
Location: India
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote Tapan Quote  Post ReplyReply Direct Link To This Post Topic: CXTPButton with rounded corners
    Posted: 17 March 2009 at 1:18am

How do I can create CXTPButton object having rounded corners like in Mac?
Can we write code to get the rounded corners or
Is there any way that I can use any image(.png, .bmp, .jpeg etc.) as background for a CXTPButton object so that I can get rounded corners like when we apply tiger skin.

Back to Top
rdhd View Drop Down
Senior Member
Senior Member

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 629
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Posted: 20 April 2009 at 4:31pm
You can always override OnPaint and draw a button to suit your needs. We do that and use custom background masks to get various shapes including elliptical. We have to built the mask and use PatBlt and BitBlt. Then we use BitPlt and MaskBlt in our code. And of course the correct rop code has to be used and you may want to handle various effects such as shifting the image on mouse down. It took me a bit of tweaking to get everything aligned properly and to get the mask created (we have some mono bitmaps that define the shapes). Probably pretty easy for a GDI jock. The key is the mask. Once we have the background image loaded we do this:

// CreateBitmapMask will fill the background of the monochrome bitmap with WHITENESS (1s) and

// fill the foreground area (where color in the image dc exists) with black (0s). It assumes

// that the hDCImage global is valid and contains the foreground/face of the button.

void OurButton::CreateBitmapMask( CBitmap* cBit, CPoint ptOffset )


CRect rect;

GetClientRect (rect);

CSize sizeButton = rect.Size();

CSize sizeImage = GetBitmapSize(m_hbmImage);

PatBlt(hDCMono, 0, 0,,, WHITENESS);

SetBkColor(hDCImage, m_bTrueColorBitmap ? s_TrueColorBackground : GetSysColor(COLOR_BTNFACE));

BitBlt(hDCMono, ptOffset.x, ptOffset.y,,, hDCImage, 0, 0, SRCCOPY);


Then when drawing the button we use MaskBlt with the mask the above code created.

Back to Top
Jouden View Drop Down

Joined: 24 July 2013
Location: Germany
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jouden Quote  Post ReplyReply Direct Link To This Post Posted: 10 September 2013 at 2:04am
Do you maybe have an example file (zip) of round and elliptical shapes?
Thanks very much,
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

This page was generated in 0.078 seconds.