Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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
}


Please help me out..

Thanks in advance
Abhishek
Posted
Updated 11-May-10 4:36am
v3

1 solution

 
Share this answer
 
v2

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