tags:

views:

23

answers:

1

I have a toolbar being displayed on the top of scroll view. When I call invalidate on scroll view, I realize both toolbar and scroll view are having screen flickering problem.

I try to have a workaround, by overriding their erase background event handler.

This method works for scroll view, but not the toolbar.

Here is my code snippet.

void MyCScrollView::OnInitialUpdate() {
    CScrollView::OnInitialUpdate();
    // ToolBar is NonFlickeringCToolBar, inherited from CToolBar
    ToolBar.Create(this);
    ToolBar.LoadToolBar(IDR_TOOLBAR);
    ToolBar.ShowWindow(SW_SHOW);
    ToolBar.SetBarStyle(CBRS_ALIGN_TOP | CBRS_SIZE_FIXED);
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
}

BOOL MyCScrollView::OnEraseBkgnd(CDC* pDC)
{
    // Override to prevent screen flickering. Works!
    return TRUE;
}

BOOL NonFlickeringCToolBar::OnEraseBkgnd(CDC* pDC) {
    // Override to prevent screen flickering. Doesn't work!
    return TRUE;
} 

Here is the screen shoot before I override the erase background event handler.

alt text

Here is the screen shoot after I override the erase background event handler. Not that, toolbar still keep flickering, with additional problem : its solid background gone till I swing my mouse cursor over its body.

alt text

I wish

  1. Make scroll view and toolbar both non-flickering
  2. Solid background for toolbar still there

Anything I had missed out?

A: 

Prevent area occupied by toolbar being redrawn.

BOOL MyCScrollView::PreCreateWindow(CREATESTRUCT& cs)
{
    // Add the WS_CLIPCHILDREN style to avoid repaint problems.
    // Without this, our toolbar will keep flickering.
    cs.style |= WS_CLIPCHILDREN;

    return CView::PreCreateWindow(cs);
}
Yan Cheng CHEOK