Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Which is better? OnPaint or OnEraseBkgnd

335 views
Skip to first unread message

Information Systems

unread,
Oct 12, 2000, 3:00:00 AM10/12/00
to

I have an MDI application that uses 2 CFormView's. I am noticing a great
deal of flicker when I switch views. What is the best way to avoid this
flicker when switching views?

Any code examples? Here is my current code.

Thanks,

Brad

void CWizVer3View::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(rect);

CBrush* pBrush = new CBrush(WIZ3_BK_BLUCOLOR);
// Select the new brush into the DC.
CBrush* oldBrush = dc.SelectObject(pBrush);
// Draw the rectangle.
dc.FillRect(rect, pBrush);
// Restore the DC and delete the brush.
dc.SelectObject(oldBrush);

delete pBrush;

// Do not call CFormView::OnPaint() for painting messages
}

nobody

unread,
Oct 12, 2000, 3:00:00 AM10/12/00
to
In article <01c03479$1fc70e00$0610210a@paloverde>
"Information Systems" <b...@cherry-semi.com> wrote:

you could try returning TRUE from the OnEraseBkgnd handler.


jj3000

unread,
Oct 12, 2000, 3:00:00 AM10/12/00
to
It's flickering because it draws things in a sequential order in front
of your eyes. If you draw everything in a memory device context first,
and then bitblt in OnPaint, you will see less/no flicker

some rough code:
OnPaint()
{
CPaintDC dc(this);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(somePen);
...draw whatever into memDC
memDC.SelectStockObject(BLACK_PEN) //deselect pen to avoid mem leak
dc.bitblt(0,0, screenwidth, screenheight, &memDC 0, 0, SRCCOPY
}

I think that's it


In article <01c03479$1fc70e00$0610210a@paloverde>,


"Information Systems" <b...@cherry-semi.com> wrote:
>
> I have an MDI application that uses 2 CFormView's. I am noticing a
great
> deal of flicker when I switch views. What is the best way to avoid
this
> flicker when switching views?
>
> Any code examples? Here is my current code.
>
> Thanks,
>
> Brad
>
> void CWizVer3View::OnPaint()
> {
> CPaintDC dc(this); // device context for painting
> CRect rect;
> GetClientRect(rect);
>
> CBrush* pBrush = new CBrush(WIZ3_BK_BLUCOLOR);
> // Select the new brush into the DC.
> CBrush* oldBrush = dc.SelectObject(pBrush);
> // Draw the rectangle.
> dc.FillRect(rect, pBrush);
> // Restore the DC and delete the brush.
> dc.SelectObject(oldBrush);
>
> delete pBrush;
>
> // Do not call CFormView::OnPaint() for painting messages
> }
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.

David Ching

unread,
Oct 18, 2000, 3:00:00 AM10/18/00
to Information Systems

Brad,

The reason it is flickering is that:

1) Windows is calling your OnEraseBackground().

2) By default, OnEraseBackground() calls DefWindowProc which paints the
entire window using the brush defined in the CLASSINFO used to create the
window.

3) Windows calls your OnPaint() function which again paints the entire window
a different color.

The flash occurs because you can briefly see the painting as a result of Step
#2 prior to the painting in step #3.


To eliminate, modify the behavior of step #2 by either:

a) Creating the window using a NULL brush

b) Override OnEraseBackground() to return TRUE so that Defwindowproc doesn't
paint anything.


David Ching, Windows Consultant
http://www.dcsoft.com

0 new messages