Usage of CScrollView

Generally speaking, we only need to rewrite 2 functions:
1. OnInitialUpdate()
void CSrcView::OnInitialUpdate()
 CPhotograph2Doc* pDoc = GetDocument();
 CSize sizeTotal;
 // TODO: calculate the total size of this view = pDoc->pSrcImg->Width(); = pDoc->pSrcImg->Height();
 SetScrollSizes(MM_TEXT, sizeTotal);
2. OnDraw()
// some drawing
SetScrollSizes(MM_TEXT, CSize(pDoc->pSrcImg->Width(), pDoc->pSrcImg->Height()));
 CChildFrame *pParentFrame = (CChildFrame *)this->GetParentFrame();
//    ResizeParentToFit();  
Probably, you may want to override the function OnEraseBkgnd();
BOOL CSrcView::OnEraseBkgnd(CDC* pDC)
 //   Set   brush   to   desired   background   color            
 CBrush   backBrush(RGB(255,   255,   255));                
 //   Save   old   brush       
 CBrush*   pOldBrush   =   pDC->SelectObject(&backBrush);  
 CRect   rect;               
 pDC->GetClipBox(&rect);           //   Erase   the   area   needed                  
 pDC->PatBlt(rect.left,,   rect.Width(),   rect.Height(),                     
 return   TRUE;  
 //return CScrollView::OnEraseBkgnd(pDC);
That’s all.

One thought on “Usage of CScrollView

  1. Feng

       // update offset point   ScreenToClient(&point);   CPoint point_offset = GetScrollPosition();                     //CClientDC   dc(this);                    //dc.DPtoLP(&point);      //CPoint   pt   =   GetDeviceScrollPosition(   )   ;      offset.x = point.x + point_offset.x;   offset.y = point.y + point_offset.y;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s