|
|||||||
|
|
|
|||||
|
|
|||||||
VC++ (MFC) Tips : View Class and View Obect
1. Change the base class of CMyAppView from CView to CScrollView
2. Because all point passed to graphic functions are based on LOGIC coordinate, but some other such as passed to mouse are based on DC, you MUST convert them firstly:
Example: add below into CMyAppView::OnMouseMove():
CString str;
CClientDC dc(this);
OnPrepareDC(&dc); //call CScrollView's function to adjust the origin point
CPoint org_p(0,0); //origin point is 0,0 on DC
dc.DPtoLP(&org_p); //adjust origin point from DC point to LOGIC point
dc.DPtoLP(&point);
dc.TextOut(org_p.x,org_p.y," ");
str.Format("%d,%d",point.x,point.y);
dc.TextOut(org_p.x,org_p.y,str);
3. Add code to initialize the scroll size:
void CMyScrollView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
4. Add code to change the scroll size:
void CMyDrawView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
SetScrollSizes(MM_TEXT,GetDocument( )->GetMyDocSize( ) );
}
5. Build CMyAppDoc::GetMyDocSize() function
Copyright (c) 1999 - 2001, robert han, all rigths are reserved.