高手帮忙解释一下这些~~越细越好~~~
CRoundButton::CRoundButton()
{
m_bDrawDashedFocusCircle = TRUE;
HBITMAP hbit=(HBITMAP)LoadImage(AfxGetInstanceHandle(),"bk.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
m_bkbitmap.Attach(hbit);
}
CRoundButton::~CRoundButton()
{
m_rgn.DeleteObject();
}
BEGIN_MESSAGE_MAP(CRoundButton, CButton)
//{{AFX_MSG_MAP(CRoundButton)
//}}AFX_MSG_MAP
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRoundButton message handlers
void CRoundButton::PreSubclassWindow()
{
CButton::PreSubclassWindow();
ModifyStyle(0, BS_OWNERDRAW);
CRect rect;
GetClientRect(rect);
// Resize the window to make it square
rect.bottom = rect.right = min(rect.bottom,rect.right);
// Get the vital statistics of the window
m_ptCentre = rect.CenterPoint();
m_nRadius = rect.bottom/2-1;
// Set the window region so mouse clicks only activate the round section
// of the button
m_rgn.DeleteObject();
SetWindowRgn(NULL, FALSE);
m_rgn.CreateEllipticRgnIndirect(rect);
SetWindowRgn(m_rgn, TRUE);
// Convert client coords to the parents client coords
}
void CRoundButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
ASSERT(lpDrawItemStruct != NULL);
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rect = lpDrawItemStruct->rcItem;
UINT state = lpDrawItemStruct->itemState;
UINT nStyle = GetStyle();
int nRadius = m_nRadius;
int nSavedDC = pDC->SaveDC();
CBrush brush;
brush.CreatePatternBrush(&m_bkbitmap);
pDC->SelectStockObject(NULL_PEN);
pDC->SelectObject(&brush);
rect.bottom = rect.right = min(rect.bottom,rect.right);
pDC->Ellipse(rect);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(255,0,0));
CString title;
GetWindowText(title);
rect.top+=10;
pDC->DrawText(title,rect,DT_CENTER);
pDC->RestoreDC(nSavedDC);
}
BOOL CRoundButton::OnEraseBkgnd(CDC * pdc)
{
return TRUE;
}