Question

I have some trouble drawing an ActiveX control. In the screenshot below you see the control after a resize in the VB6 IDE. The control's outline from before the resize is still shown on the left-hand side of the control:

enter image description here

Here is the code that draws a black ellipsis with a red Z:

void CzFileIoXCtrl::OnDraw(CDC* pdc, 
                           const CRect& rcBounds, 
                           const CRect& rcInvalid)
{
    if (!pdc)
    {
        return;
    }

    pdc->SetBkMode(TRANSPARENT); 
    pdc->SelectObject(CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH)));
    pdc->Ellipse(rcBounds.left, rcBounds.top, 
                 rcBounds.left + rcBounds.Width(), 
                 rcBounds.top + rcBounds.Height());       

    HFONT font = CreateFont(int(rcBounds.Height() * 0.7),
                            int(rcBounds.Width()  * 0.5),
                            0, 0, FW_BLACK, FALSE, FALSE, FALSE,
                            ANSI_CHARSET,
                            OUT_DEFAULT_PRECIS,
                            CLIP_DEFAULT_PRECIS,
                            CLEARTYPE_QUALITY,
                            FF_DECORATIVE, NULL);
    pdc->SelectObject(font);
    pdc->SetTextColor(RGB(255, 0, 0));
    DRAWTEXTPARAMS params = { sizeof(DRAWTEXTPARAMS), 1, 0, 0, 1 };
    RECT bounds = rcBounds;
    CString z(L"Z");
    pdc->DrawTextEx(z, &bounds, DT_CENTER | DT_VCENTER | DT_SINGLELINE, &params);
}

How can I clear the drawing area?

Was it helpful?

Solution

I managed to reproduce this in the vb form editor. It looks like the problem comes because you do not draw anything outside the ellipse. So, you can draw a rectangle in the entire area like this before drawing anything in OnDraw().

pdc->FillRect( rcBounds, &CBrush(TranslateColor( AmbientBackColor() )) );

I tested this and is working fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top