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 drawingSetScrollSizes(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.
可以用下面的代码得到一个点相对于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;