Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Bitmap m_bitmap. How I make it rounded corner so that I Put this on Button as OnEraseBackground or OnPaint to have a Rounded look. Please Any Help. My code below make Button Round but When I hover the Button it reverse to Rectangle shape.

What I have tried:

CDC dc2;
			dc2.CreateCompatibleDC(pDC);
			CBitmap *oldbmap = dc2.SelectObject(&m_bitmap);

			/*We copy the bitmap into the DC*/
			pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &dc2, 0, 0, SRCCOPY);
			dc2.SelectObject(oldbmap);


			CRgn rgn;
			rgn.CreateRoundRectRgn(0, 0, rect.Width(), rect.Height(), m_ptRound.x, m_ptRound.y);
			SetWindowRgn(static_cast<HRGN>(rgn.GetSafeHandle()), 1);
			rgn.Detach();
Posted
Updated 4-Sep-18 0:03am
Comments
11917640 Member 3-Sep-18 2:37am    
Call SetWindowRgn before BitBlt.
Shahzad Naseer 3-Sep-18 22:53pm    
Thanks....
Rick York 3-Sep-18 12:27pm    
I believe 11917640 is correct.

Also, there are several articles at this site that implement buttons with rounded corners. You might want to have a look at a few of them.
Shahzad Naseer 3-Sep-18 23:15pm    
This is true. Thanks

1 solution

Read the article Guide to WIN32 Regions for basic understanding. A nice article of the usage is CContourBitmap - A Region Creator which describes a nice use case of the regions for bitmaps.

Tip: create the rounded bitmap once and store it for later usage
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900