Question

I'm experiencing flicker when rotating a rectangle but not when moving a rectangle, even though I'm using the same show function. It is a floor layout scenario.

Some images to illustrate. The red rectangle in the centre is selected and moved:

Move example

But when trying to rotate the following happens:

Rotate example

The code used to rotate a rectangle:

m_pDrawRect->SetRelativeAngle(point, m_pntLast, RECT_SELECTED | RECT_RECURSIVE);
m_pDrawRect->SetRelativePosition(point, m_pntLast, RECT_SELECTED |RECT_RECURSIVE);
CRecordDC dcRecord(m_pMemDC->GetDC(this, TRUE));
m_pDrawRect->Draw(&dcRecord, RECT_SELECTED);
m_pMemDC->Show(this);

The show function:

Show(CWnd *pWnd)
{
CDC *pMainWnd=pWnd->GetDC();
pMainWnd->BitBlt(rcPaint.left, rcPaint.top, rcPaint.Width(), rcPaint.Height(), m_pMemDC, rcPaint.left, rcPaint.top, SRCCOPY);
pWnd->ReleaseDC(pMainWnd);
Was it helpful?

Solution

I managed to fix it by replacing the show function with:

CRect rcPaint;
this->GetClientRect(rcPaint);
CDC *pDCOld = m_pMemDC->GetDC(this, TRUE);
CDC pDCTemp;
pDCTemp.CreateCompatibleDC(pDCOld);
CMemDC memDC(pDCTemp, rcPaint);
CDC* pDC = &memDC.GetDC();
pDC->BitBlt(rcPaint.left, rcPaint.top, rcPaint.Width(), rcPaint.Height(), pDCOld,
rcPaint.left, rcPaint.top, SRCCOPY);
Invalidate();

The object this refers to the current CView object. This works but it's slightly unresponsive.

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