Trailing draws and clearing the Draw Region

  • Thread starter Thread starter Safiullah
  • Start date Start date
S

Safiullah

Guest
In an MDI application, I am drawing on the frame on a MouseMove event. Naturally I get a trail of objects in the frame due to successive draws, which I am trying to eliminate.

I have read up all I can find, and have tried a couple of ideas as follows:

1> I get the BoundsRect by calling CDC's GetBoundsRect() and tried filling the region. For some reason this does not work.

2> Call The GetBoundsRect with DCB_RESET and DCB_DISABLE/DCB_ENABLE. This too does not have the affect I had in mind.

3> Drawing the same object in the previous position with the background color. This works, but I sometimes get some artifacts.

Code Snippets are as follows (I am using the Scribble example code as the basis):

oid CFuncBlockTestView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CFuncBlockTestDoc * pDoc = GetDocument();
CSize sizeDoc, sizeNum(1, 1), sizeDenom(1, 1);
CBrush objBkBrush(RGB(255, 255, 255));
RECT objBkRect;
int xLogPixPerInch(0), yLogPixPerInch(0);
long xExt(0), yExt(0);

CScrollView::OnPrepareDC(pDC, pInfo);

pDC->SetMapMode(MM_ANISOTROPIC);
sizeDoc = pDoc->m_rectNetworkRect.Size();
sizeDoc.cy = -sizeDoc.cy;

pDC->SetWindowExt(sizeDoc);

xLogPixPerInch = pDC->GetDeviceCaps(LOGPIXELSX);
yLogPixPerInch = pDC->GetDeviceCaps(LOGPIXELSY);

xExt = (long)sizeDoc.cx * xLogPixPerInch * sizeNum.cx;
xExt /= 100 * (long)sizeDenom.cx;
yExt = (long)sizeDoc.cy * yLogPixPerInch * sizeNum.cy;
yExt /= 100 * (long)sizeDenom.cy;
pDC->SetViewportExt((int)xExt, (int)-yExt);

pDC->SetBkMode(TRANSPARENT);
pDC->SetBkColor(RGB(255, 255, 255));
pDC->GetBoundsRect(&objBkRect, DCB_RESET | DCB_DISABLE);
objBkRect.bottom = -objBkRect.bottom;
pDC->FillRect(&objBkRect, &objBkBrush);
}

The MouseMove Event

void CFuncBlockTestView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//..some declarations
CClientDC objClientDC(this);
CBrush objBkgnd(objClientDC.GetBkColor());

RECT rectClientRect;
unsigned int ret_val = 0;

OnPrepareDC(&objClientDC);


//Reset the Client DC (Clear Draw area)
// ret_val = objClientDC.GetBoundsRect(&rectClientRect, DCB_RESET);
// objClientDC.FillRect(&rectClientRect, &objBkgnd);

//...some code
DrawBlock(&objClientDC, pLastComponent, point);

//...some more code

CScrollView::OnMouseMove(nFlags, point);
}


Please let me know if I should post more information.

Continue reading...
 
Back
Top