// Eg9_4View.cpp : implementation of the CEg9_4View class
//

#include "stdafx.h"
#include "Eg9_4.h"

#include "Eg9_4Doc.h"
#include "Eg9_4View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEg9_4View

IMPLEMENT_DYNCREATE(CEg9_4View, CScrollView)

BEGIN_MESSAGE_MAP(CEg9_4View, CScrollView)
	//{{AFX_MSG_MAP(CEg9_4View)
	ON_WM_LBUTTONUP()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEg9_4View construction/destruction
int j=0;
CEg9_4View::CEg9_4View()
{
	// TODO: add construction code here

}

CEg9_4View::~CEg9_4View()
{
}

BOOL CEg9_4View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEg9_4View drawing

void CEg9_4View::OnDraw(CDC* pDC)
{
	CEg9_4Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	pDC->SetMapMode(MM_LOENGLISH);
	char buffer[45];
	CString str;
	for(int i=0;i<j;i++)
	{
     str=ltoa(i,buffer,10);
	pDC->TextOut(0,-i*20,"´òÓ¡Ô¤ÀÀ"+str);
	}
	CRect rect;
	GetClientRect(&rect);
	CSize  doc(100,j*20);
	CSize page(rect.right,rect.bottom);
	CSize line(0,20);
	SetScrollSizes(MM_LOENGLISH, doc,page,line);

	// TODO: add draw code for native data here
}

void CEg9_4View::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_LOENGLISH, sizeTotal);
	
}

/////////////////////////////////////////////////////////////////////////////
// CEg9_4View printing

BOOL CEg9_4View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	

	return DoPreparePrinting(pInfo);
}

void CEg9_4View::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// TODO: add extra initialization before printing
	 pDC->SetMapMode(MM_LOENGLISH);
	CEg9_4Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	int pageh=pDC->GetDeviceCaps(VERTRES);
    int log=pDC->GetDeviceCaps(LOGPIXELSY);
    int pagenum=(int)(log*0.2*j/pageh+1);
 //   char buffer[45];
 //   AfxMessageBox(ltoa(pagenum,buffer,10));
	pInfo->SetMaxPage(pagenum);
	
}

void CEg9_4View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CEg9_4View diagnostics

#ifdef _DEBUG
void CEg9_4View::AssertValid() const
{
	CScrollView::AssertValid();
}

void CEg9_4View::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CEg9_4Doc* CEg9_4View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEg9_4Doc)));
	return (CEg9_4Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEg9_4View message handlers

void CEg9_4View::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
   j=j+5;
   Invalidate();

	CScrollView::OnLButtonUp(nFlags, point);
}

void CEg9_4View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pDC->IsPrinting())
    {	
	pDC->SetMapMode(MM_LOENGLISH);
	int pageh=pDC->GetDeviceCaps(VERTRES);
    int origin=pageh*(pInfo->m_nCurPage-1);
	CPoint point(0,-5000);
	pDC->SetViewportOrg(point);
	}	
	CScrollView::OnPrepareDC(pDC, pInfo);
}

void CEg9_4View::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	OnDraw(pDC);
	
	CScrollView::OnPrint(pDC, pInfo);
}
