CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2004
    Posts
    91

    How to avoid flickering of controls on CFormview

    Hi,

    I have a CFormView with many controls. When I try to resize the view i.e child frame, there is a lot of flickering of all the controls. Can anyone please help to to remove this filckering of controls.

    Thanks
    Madhavi

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: How to avoid flickering of controls on CFormview

    Quote Originally Posted by CCC
    Hi,

    I have a CFormView with many controls. When I try to resize the view i.e child frame, there is a lot of flickering of all the controls. Can anyone please help to to remove this filckering of controls.

    Thanks
    Madhavi
    I hope I'm wrong, but as I know you cannot avoid this.
    That's it.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: How to avoid flickering of controls on CFormview

    Well, I had done something for dialogs and they might work here as well. Not sure though. First of all you have to set the form's "Clip children" style then, as an advanced feature, try to exlucde the controls from the erase background region of the form.
    Har Har

  4. #4
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: How to avoid flickering of controls on CFormview

    Here is one way of implementing the OnEraseBkgnd so that the controls on the form do not get erased when the background is redrawn. You will have to populate the id list witht he controls on your form view, but it should work from there:

    BOOL CRefinementProView::OnEraseBkgnd(CDC* pDC)
    {
    CRect clip;
    pDC->SaveDC();
    static int dont_erase_indexes[] =
    {
    IDC_TITLE_LABEL,
    IDC_TITLE,
    IDC_ANALYST_LABEL,
    IDC_ANALYST
    };

    for (int i = 0; i < sizeof(dont_erase_indexes) / sizeof(int); i++)
    {
    CWnd *pWnd = GetDlgItem(dont_erase_indexes[i]);
    if (pWnd && pWnd->IsWindowVisible())
    {
    pWnd->GetWindowRect(&clip); // get rect of the control
    ScreenToClient(&clip);
    pDC->ExcludeClipRect(&clip);
    }
    }

    pDC->GetClipBox(&clip);
    pDC->FillSolidRect(clip, GetSysColor(COLOR_BTNFACE));
    pDC->RestoreDC(-1);
    return FALSE;
    }
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  5. #5
    Join Date
    Aug 2000
    Location
    High on a hill in the Ohio valley
    Posts
    711

    Re: How to avoid flickering of controls on CFormview

    This is what I used for a flicker problem I had on CFormView. Not sure if this was for my specific sitation or if it might work for you also.

    Place in OnIntialUpdate()

    Code:
    ModifyStyle( NULL , WS_CLIPCHILDREN , 0 ); //For flicker free window painting (resizing)

  6. #6
    Join Date
    Aug 2004
    Posts
    91

    Re: How to avoid flickering of controls on CFormview

    Hi,

    Thanks for your help.
    I am able to remove flickering now...

    Madhavi

  7. #7
    Join Date
    Aug 2009
    Posts
    13

    Re: How to avoid flickering of controls on CFormview

    I tried these techniques.

    This by-passes OnEraseBkgnd:
    Code:
    void CTRChartFormView::OnInitialUpdate()
    {
    	CFormView::OnInitialUpdate();
    ...
    
    	ModifyStyle( NULL , WS_CLIPCHILDREN , 0 ); 
    ...
    
    }
    I still get flicker.

    I have a single Picture Control that occupies the entire form view. The image is refreshed in OnSize:
    Code:
    void CChartFormView::OnSize(UINT nType, int cx, int cy) 
    {
    	CFormView::OnSize(nType, cx, cy);
    	
    	CRect rect(0,0,cx,cy);
    
    	if(IsChartInitialized())
    	{
    		m_ChartViewer.MoveWindow(&rect, FALSE);
    		
    		drawChart(&m_ChartViewer);
    	}
    
    }
    Any ideas?

    Thanks
    Last edited by CCmdTarget; September 14th, 2009 at 04:25 AM.

  8. #8
    Join Date
    Feb 2005
    Posts
    2,160

    Re: How to avoid flickering of controls on CFormview

    Quote Originally Posted by CCmdTarget View Post
    I tried these techniques.

    This by-passes OnEraseBkgnd:
    Code:
    void CTRChartFormView::OnInitialUpdate()
    {
    	CFormView::OnInitialUpdate();
    ...
    
    	ModifyStyle( NULL , WS_CLIPCHILDREN , 0 ); 
    ...
    
    }
    This does NOT bypass OnEraseBackground. It only tells the view to NOT paint the background of child windows. Since your picture control is the whole client area, it doesn't matter anyway.


    I still get flicker.

    I have a single Picture Control that occupies the entire form view. The image is refreshed in OnSize:
    Code:
    void CChartFormView::OnSize(UINT nType, int cx, int cy) 
    {
    	CFormView::OnSize(nType, cx, cy);
    	
    	CRect rect(0,0,cx,cy);
    
    	if(IsChartInitialized())
    	{
    		m_ChartViewer.MoveWindow(&rect, FALSE);
    		
    		drawChart(&m_ChartViewer);
    	}
    
    }
    Any ideas?

    Thanks
    Whatever it is that your m_ChartViewer class is derived from, that is probably where you need to put your attention. It's obviously a CWnd at some point so it probaly has a OnPaint override and that is probably where the flicker is coming from.

  9. #9
    Join Date
    Aug 2009
    Posts
    13

    Re: How to avoid flickering of controls on CFormview

    Thanks for the response. I suspected that might be the issue.

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to avoid flickering of controls on CFormview

    At the beginning of your OnSize handler, call LockWindowUpdate(...), do your sizing and call UnlockWindowUpdate(...) before exiting the OnSize method.

  11. #11
    Join Date
    Aug 2009
    Posts
    13

    Re: How to avoid flickering of controls on CFormview

    Thanks for the suggestion. It works for the dialog. The image still flickers. I will double buffer the drawing in the ChartViewer class.

  12. #12
    Join Date
    Jun 2006
    Posts
    645

    Re: How to avoid flickering of controls on CFormview

    Hey...not sure about this.....had watched this long back....
    It is for drawing in window. Controls BTW are drawn on to the form. See if that helps.
    Just a hint, if the view class in the demo inherits from CScrollView, then instead of inheriting your form view from CSrollView, just inherit it from the view in the tutorial. Seems like a round about way, but keep it as ur last option. Although, double buffering would be a gr8 option if u could get it done....
    Regards,
    Bhushan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured