Print Page | Close Window

CXTPButton with rounded corners

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=13705
Printed Date: 19 April 2024 at 7:48pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPButton with rounded corners
Posted By: Tapan
Subject: CXTPButton with rounded corners
Date 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



Replies:
Posted By: rdhd
Date 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, 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.



Posted By: Jouden
Date Posted: 10 September 2013 at 2:04am
Hello,
 
Do you maybe have an example file (zip) of round and elliptical shapes?
 
Thanks very much,
Regards,
Jc



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net