圆形按钮
前次看到一个贴子,要圆形按钮的代码偶找到了
贴子原出处及下载源码:
vckbase/english/code/buttonctrl/btn_circular_button.shtml.htm
首要代码:
//MyBtn.cpp:implementationfile
//
#includestdafx.h
#includeMyBtn.h
#includeMemDC.h
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CMyBtn
CMyBtn::CMyBtn()
{
}
CMyBtn::~CMyBtn()
{
}
BEGIN_MESSAGE_MAP(CMyBtn,CButton)
//{{AFX_MSG_MAP(CMyBtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CMyBtnmessagehandlers
voidCMyBtn::SetRound(void)
{
HRGNrgn;
CRectwrect;
GetClientRect(wrect);
SetWindowRgn(NULL,FALSE);
rgn=CreateEllipticRgn(wrect.left,wrect.top,
wrect.right,wrect.bottom);
SetWindowRgn(rgn,TRUE);
}
voidCMyBtn::GradientFill(CDC
pDC,CRect
pRect)
{
CBrush
pBrush;
for(inti=0;inewCBrush(RGB(0,0,255-(i
4)));
}
intnWidth=pRect-gt;Width();
intnHeight=pRect-gt;Height();
CRectrect;
for(i=0;iFillRect(rect,pBrush);
}
for(i=0;ivoidCMyBtn:<imgsrc="biggrin.gif"smilieid="3"border="0"alt=""/>rawItem(LPDRAWITEMSTRUCTlpDrawItemStruct)
{
//TODO:Addyourcodetodrawthespecifieditem
CRectRect=lpDrawItemStruct-gt;rcItem;
CDC
pDC=CDC::FromHandle(lpDrawItemStruct-gt;hDC);
CRgnrgn;
CRectrect;
rect=Rect;
UINTstate=lpDrawItemStruct-gt;itemState;
CMemDC
pMemDC=newCMemDC(pDC,Rect);
CBrushhbr;
hbr.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
//pDC-gt;FillRect(Rect,hbr);
pMemDC-gt;FillRect(Rect,hbr);
《VisualC++高档编程及其项目使用开发》配套代码\第7章\MyFieldTry\StdAfx.cpp
《VisualC++高档编程及其项目使用开发》配套代码\第7章\MyFieldTry\StdAfx.h
(The last time I saw a post, I wanted the code for the circular button
even found
The original source of the post and the download source code:
vckbase/english/code/buttonctrl/btn_circular_button.shtml.htm
Primary code:
//MyBtn.cpp:implementationfile
//
#includestdafx.h
#includeMyBtn.h
#includeMemDC.h
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE=__FILE__;
#endif
///////////////////////////////////////////// //////////////////////////
//CMyBtn
CMyBtn::CMyBtn()
{
}
CMyBtn::~CMyBtn()
{
}
BEGIN_MESSAGE_MAP(CMyBtn, CButton)
//{{AFX_MSG_MAP(CMyBtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
///////////////////////////////////////////// //////////////////////////
//CMyBtnmessagehandlers
voidCMyBtn::SetRound(void)
{
HRGNrgn;
CRectwrect;
GetClientRect(wrect);
SetWindowRgn(NULL, FALSE);
rgn=CreateEllipticRgn(wrect.left,wrect.top,
wrect.right,wrect.bottom);
SetWindowRgn(rgn,TRUE);
}
voidCMyBtn::GradientFill(CDC
pDC,CRect
pRect)
{
CBrush
pBrush;
for(inti=0;inewCBrush(RGB(0,0,255-(i
4)));
}
intnWidth=pRect-gt;Width();
intnHeight=pRect-gt;Height();
CRectrect;
for(i=0;iFillRect(rect,pBrush);
}
for(i=0;ivoidCMyBtn:<imgsrc="biggrin.gif"smilieid="3"border="0"alt=""/>rawItem(LPDRAWITEMSTRUCTlpDrawItemStruct)
{
//TODO:Addyourcodetodrawthespecifieditem
CRectRect=lpDrawItemStruct-gt;rcItem;
CDC
pDC=CDC::FromHandle(lpDrawItemStruct-gt;hDC);
CRgnrgn;
CRectrect;
rect=Rect;
UINTstate=lpDrawItemStruct-gt;itemState;
CMemDC
pMemDC=newCMemDC(pDC,Rect);
CBrushhbr;
hbr.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
//pDC-gt;FillRect(Rect,hbr);
pMemDC-gt;FillRect(Rect,hbr);
"Visual C Advanced Programming and Project Development" Supporting Code\Chapter 7\MyFieldTry\StdAfx.cpp
"Visual C Advanced Programming and Project Development" Supporting Code\Chapter 7\MyFieldTry\StdAfx.h)
页:
[1]