如何绘制圆形按钮 [英] How to draw round button
本文介绍了如何绘制圆形按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须创建一个包含三个图像的矩形按钮,一个用于左圆形,一个用于按钮的中间部分,一个用于右侧圆形.我只是想知道如何在按钮上添加这些圆形图像.因此该按钮具有圆形形状.这是我的代码,可以在其中添加中间图像.
Hi,
I have to create a round rect button with three images, one for left round shape one for middle portion of button and one for right side round shape. I just wanted to know how to add these round images on the button. So that button has a round shape. Here is my code in which I am able to add middle image.
void CRoundButton2::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
ASSERT (pDC != NULL);
// Should Buttons be generated?
bool bGenerate = !m_rBtnSize.EqualRect(&lpDrawItemStruct->rcItem) || m_bRedraw;
// If Rectangles of Button are not the same
if (bGenerate)
{
// Generate Bitmap to hold Buttons
GenButtonBMPs(pDC, lpDrawItemStruct->rcItem);
// Redraw done
m_bRedraw = false;
}
// Generate DC to draw in Memory
CDC *MemDC = new CDC();
MemDC->CreateCompatibleDC(pDC);
HGDIOBJ hOldBmp = MemDC->SelectObject(m_tBmpBtn);
CString sActualCaption;
// Get actual caption
GetWindowText(sActualCaption);
// Check, if caption has changed
if (sActualCaption != m_sOldCaption)
bGenerate = true;
// Store old caption
m_sOldCaption = sActualCaption;
// If Rectangles of Button are not the same
if (bGenerate)
{
// Draw Buttons
DrawButtonFace(MemDC);
// Draw Button-Caption
DrawButtonCaption(MemDC);
}
int nButtonState;
nButtonState = BS_ENABLED;
if (m_bIsHotButton && m_bMouseOnButton)
nButtonState = BS_HOT;
if ((lpDrawItemStruct->itemState & ODS_DISABLED) == ODS_DISABLED)
nButtonState = BS_DISABLED;
else
{
if ((lpDrawItemStruct->itemState & ODS_SELECTED) == ODS_SELECTED)
nButtonState = BS_PRESSED;
else
{
if (this->m_bIsChecked)
{
nButtonState = BS_CLICKED;
}
}
}
CBitmap bitmap2;
bitmap2.LoadBitmap(IDB_BITMAP1);
BITMAP bmpInfo;
bitmap2.GetBitmap(&bmpInfo);
CBitmap* pOldBitmap = MemDC->SelectObject(&bitmap2);
//int nX = m_rBtnSize.left + (m_rBtnSize.Width() - bmpInfo.bmWidth) / 2;
//int nY = m_rBtnSize.top + (m_rBtnSize.Height() - bmpInfo.bmHeight) / 2;
// Copy correct Bitmap to Screen
for ( int i = 0 ; i<117 ; i++)
{
MemDC->SelectObject(bitmap2);
pDC->BitBlt(0+i,0,bmpInfo.bmWidth,bmpInfo.bmHeight, MemDC,0, 0, SRCCOPY);
//MemDC->SelectObject(hOldBmp);
MemDC->SelectObject(pOldBitmap);
}
UINT state = lpDrawItemStruct->itemState; //Get state of the button
if ( (state & ODS_SELECTED) ) // If it is pressed
pDC->DrawEdge(m_rBtnSize,EDGE_SUNKEN,BF_RECT); // Draw a sunken face
}
请帮帮我..
在此先感谢
Abhishek
Please help me out..
Thanks in advance
Abhishek
推荐答案
在CP上有一些示例文章-
http://www.codeproject.com/KB/buttons/roundbuttons.aspx [ ^ ]
http://www.codeproject.com/KB/buttons/CRoundButton2.aspx [ ^ ]
There are some example articles here on CP -
http://www.codeproject.com/KB/buttons/roundbuttons.aspx[^]
http://www.codeproject.com/KB/buttons/CRoundButton2.aspx[^]
这篇关于如何绘制圆形按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文