Circular Push Button

Download Source. 50KB.
// MyBtn.cpp : implementation file

#include "stdafx.h"
#include "MyBtn.h"

#include "MemDC.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;

// CMyBtn




// CMyBtn message handlers

void CMyBtn::SetRound(void)
	HRGN rgn;
	CRect wrect;
    SetWindowRgn( NULL, FALSE );
	rgn = CreateEllipticRgn( wrect.left,,
								wrect.right, wrect.bottom );

	SetWindowRgn(rgn, TRUE);	

void CMyBtn::GradientFill (CDC* pDC, CRect* pRect)
    CBrush* pBrush[64];

    for (int i=0; i<64; i++) 
		pBrush[i] = new CBrush (RGB (0, 0, 255 - (i * 4)));

    int nWidth = pRect->Width ();
    int nHeight = pRect->Height ();
    CRect rect;

    for (i=0; iFillRect (&rect, pBrush[(i * 63) / nHeight]);

    for (i=0; i<64; i++)
        delete pBrush[i];

void CMyBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
	// TODO: Add your code to draw the specified item
	CRect Rect = lpDrawItemStruct->rcItem;
	CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	CRgn rgn;
	CRect rect;

	rect = Rect;

	UINT state = lpDrawItemStruct->itemState;

	CMemDC	*pMemDC = new CMemDC( pDC, Rect);
	CBrush hbr;
	//pDC->FillRect( &Rect, &hbr);
	pMemDC->FillRect( &Rect, &hbr);
	if( !(state & ODS_DISABLED) )
		if (state & ODS_SELECTED)
			CPen pen( PS_SOLID, 2, GetSysColor( COLOR_3DHILIGHT ) );
			CPen *pPen;
			CPoint start, end;

			start.x = rect.left;
			start.y = rect.bottom;		
			end.x = rect.right;
			end.y =;

			rect.left += 2; += 2;
			rect.right -= 2;
			rect.bottom -= 2;

			pPen = pMemDC->SelectObject( &pen );
			pMemDC->Arc( &rect, start, end );
			pMemDC->SelectObject( pPen );

	rgn.CreateEllipticRgn( rect.left,, 
							rect.right, rect.bottom );
	pMemDC->SelectClipRgn( &rgn );	
	GradientFill( pMemDC, &Rect );


	CString title;
	GetWindowText( title );
	if( title.GetLength() != 0 )
		DrawWhiteText( pMemDC, &Rect, title );

	delete pMemDC;

void CMyBtn::DrawWhiteText(CDC* pDC, CRect* pRect, CString& text )
    CFont font;
    int nHeight = -16;

    font.CreateFont (nHeight, 0, 0, 0, FW_BOLD,
        FF_DONTCARE, "Times New Roman");

    pDC->SetTextColor(RGB (255, 255, 255));

    CFont* pOldFont = pDC->SelectObject (&font);
    pDC->DrawText (text, -1, pRect, DT_SINGLELINE | DT_CENTER |

    pDC->SelectObject (pOldFont);


  • Your Feet Will like The nike jordan Sneakers and like the Encounter

    Posted by BotsictastHom on 04/22/2013 08:24pm

    Hello there! I know this is kinda off topic however I'd figured I'd ask. Would you be interested in trading links or maybe guest writing a blog post or vice-versa? My site covers a lot of the same subjects as yours and I think we could greatly benefit from each other. If you might be interested feel free to shoot me an email. I look forward to hearing from you! Fantastic blog by the way! [url=]cheap lebron 10[/url]|

  • new code

    Posted by Legacy on 10/01/2003 12:00am

    Originally posted by: kunix

    I make new version code.

    If you need project file, e-mail to me..

    It is dialog-based project code.

  • ?use in a dialog box

    Posted by Legacy on 09/11/2003 12:00am

    Originally posted by: Julia

    I am trying to use this button to a dialogbox of the application. However, the round shape does not appear. Is there any difference when using it under a formview and a dialogbox? Thank you for your help.

  • How to make background transparent

    Posted by Legacy on 03/05/1999 12:00am

    Originally posted by: Gordon Lam

    Do you know how to make the background of the button become

  • Circular Buttons

    Posted by Legacy on 09/27/1998 12:00am

    Originally posted by: Ahsan

    These buttons are very useful in improving interface.
    These are pretty smart buttons.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date