CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2001
    Posts
    2,455

    Paint back color of CScrollView derived class.

    I am using a memory dc to do the drawing, therefore, I override OnEraseBkgnd(...) and return FALSE. In the Ondraw(...) function for my
    CScrollView class, I attempt to repaint the background color to gray.

    Why does it not get painted.
    Code:
    void CTaskPlan::OnDraw(CDC* pDC)
    {
    	QBufferDC dc(pDC, SRCCOPY);
    
    	CRect rcClient;
    	GetClientRect(&rcClient);
    	dc.FillSolidRect(&rcClient, RGB(128,128,128));
    	m_Pages[0].OnDraw(&dc);
     }
    The page gets drawn so I know the dc is good. But the background color is not set.

    Any ideas?

    Mike B

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757

    Re: Paint back color of CScrollView derived class.

    inside QBufferDC constructor?

    select object brush

    Kuphryn

  3. #3
    Join Date
    Feb 2001
    Posts
    2,455

    Re: Paint back color of CScrollView derived class.

    Quote Originally Posted by kuphryn
    inside QBufferDC constructor?

    select object brush

    Kuphryn
    Sheeesh, always something really dumb. I had to normalize rcClient CRect object. Whoops, forgot to add, also had to convert from device to logical units.

    Mike B
    Last edited by MikeB; July 6th, 2006 at 01:45 PM.

  4. #4
    Join Date
    Jun 2006
    Posts
    645

    Re: Paint back color of CScrollView derived class.

    Or you can add an handler fucntion into your view class <OnEraseBkgnd>
    as under:

    BOOL CMHSDProjectView::OnEraseBkgnd(CDC* pDC)
    {
    // TODO: Add your message handler code here and/or call default

    // This code is added for the colored background of the document view

    CBrush brNew(RGB(192,192,255)); //Creates a blue brush
    CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&brNew);

    CRect rc;
    pDC->GetClipBox(rc); // Gets the co-ordinates of the client
    // area to repaint.
    pDC->PatBlt(0,0,rc.Width(),rc.Height(),PATCOPY);
    // Repaints client area with current brush.
    pDC->SelectObject(pOldBrush);

    return TRUE; // Prevents the execution of return
    // CView::OnEraseBkgnd(pDC) statement

    return CView::OnEraseBkgnd(pDC);
    }

    Regards,
    Bhushan.

  5. #5
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Paint back color of CScrollView derived class.

    Use SetClassLong(m_hWnd, GCL_HBRBACKGROUND, (LONG)(HBRUSH)m_Brush)
    in OnInitialUpdate or anywhere you want to set new color for view’s background.

    Use your own CBrush object or any predefined system brushes (COLOR_xxx).
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

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