ActiveX


OnDraw.


OnDraw( ):

void CMyCtrlCtrl::OnDraw(

CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)

{

CPen pen;

CBrush foreBrush, backBrush;

CPoint points[3];

pdc->SaveDC();

pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));

ULONG foreColor = TranslateColor(GetForeColor());

backBrush.CreateSolidBrush(TranslateColor(AmbientBackColor()));

foreBrush.CreateSolidBrush(GetSelected() ? foreColor : TranslateColor(m_selectColor));

pdc->FillRect(rcBounds, &backBrush);

pdc->SelectObject(&pen);

pdc->SelectObject(&foreBrush);

switch (m_nShape)

{

case 0:

pdc->Ellipse(rcBounds);

break;

case 1:

pdc->Rectangle(rcBounds);

break;

case 2:

points[0].x = rcBounds.left;

points[0].y = rcBounds.bottom - 1;

points[1].x = (rcBounds.left + rcBounds.right - 1) / 2;

points[1].y = rcBounds.top;

points[2].x = rcBounds.right - 1;

points[2].y = rcBounds.bottom - 1;

pdc->Polygon(points, 3);

break;

}

CFont *pOldFont;

TEXTMETRIC tm;

//pdc->SetTextColor(TranslateColor(m_textColor));

//pdc->SetBkMode(TRANSPARENT);

 

CString strCaption = GetText();

pOldFont = SelectStockFont(pdc);

pdc->GetTextMetrics(&tm);

pdc->SetTextAlign(TA_CENTER|TA_TOP);

 

pdc->ExtTextOut((rcBounds.left + rcBounds.right)/2,(rcBounds.top + rcBounds.bottom - tm.tmHeight)/2,

ETO_CLIPPED, rcBounds, strCaption, strCaption.GetLength(),NULL);

pdc->RestoreDC(-1);

}

, (TextColor) , m_textColor, GetTextColor setTextColor, OnDraw, ( ).

 




- -  - -  - -