CXTPButton with rounded corners |
Post Reply |
Author | |
Tapan
Newbie Joined: 25 May 2006 Location: India Status: Offline Points: 3 |
Post Options
Thanks(0)
Posted: 17 March 2009 at 1:18am |
Hello,
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. Thanks, Tapan |
|
rdhd
Senior Member Joined: 13 August 2007 Location: United States Status: Offline Points: 891 |
Post Options
Thanks(0)
|
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, sizeButton.cx, sizeButton.cy, WHITENESS); SetBkColor(hDCImage, m_bTrueColorBitmap ? s_TrueColorBackground : GetSysColor(COLOR_BTNFACE)); BitBlt(hDCMono, ptOffset.x, ptOffset.y, sizeImage.cx, sizeImage.cy, hDCImage, 0, 0, SRCCOPY); } Then when drawing the button we use MaskBlt with the mask the above code created. |
|
Jouden
Newbie Joined: 24 July 2013 Location: Germany Status: Offline Points: 4 |
Post Options
Thanks(0)
|
Hello,
Do you maybe have an example file (zip) of round and elliptical shapes? Thanks very much, Regards, Jc
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |