Usage of CScrollView


Generally speaking, we only need to rewrite 2 functions:
1. OnInitialUpdate()
void CSrcView::OnInitialUpdate()
{
 CScrollView::OnInitialUpdate();
 
 CPhotograph2Doc* pDoc = GetDocument();
 CSize sizeTotal;
 // TODO: calculate the total size of this view
 sizeTotal.cx = pDoc->pSrcImg->Width();
 sizeTotal.cy = 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();
    pParentFrame->RecalcLayout();
//    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.top,   rect.Width(),   rect.Height(),                     
  PATCOPY);               
 pDC->SelectObject(pOldBrush);  
             
 return   TRUE;  
 //return CScrollView::OnEraseBkgnd(pDC);
}
 
That’s all.

One thought on “Usage of CScrollView

  1. Feng

    可以用下面的代码得到一个点相对于Document原点的坐标。
       // 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;

    Reply

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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