C ++ cbitmap圆角 [英] C++ cbitmap round corners

查看:85
本文介绍了C ++ cbitmap圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个位图m_bitmap。我如何使它圆角,以便我把它放在按钮上作为OnEraseBackground或OnPaint具有圆角外观。请任何帮助。我的代码在下面制作Button Round,但是当我将鼠标悬停在它上面时,它会反转为矩形形状。



我尝试了什么:



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();

推荐答案

阅读文章 WIN32地区指南以获得基本的理解。一篇很好的文章是 CContourBitmap - 一个地区创建者,它描述了一个不错的用例位图的区域。



提示:创建一个圆形位图并存储以供以后使用
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


这篇关于C ++ cbitmap圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆