www.pudn.com > Cimage.zip > DEMOVIEW.CPP


// demoView.cpp : implementation of the CDemoView class 
// 
 
#include "stdafx.h" 
#include "cimage.h" 
#include "demo.h" 
 
#include "demoDoc.h" 
#include "demoView.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CDemoView 
 
IMPLEMENT_DYNCREATE(CDemoView, CScrollView) 
 
BEGIN_MESSAGE_MAP(CDemoView, CScrollView) 
	//{{AFX_MSG_MAP(CDemoView) 
		// NOTE - the ClassWizard will add and remove mapping macros here. 
		//    DO NOT EDIT what you see in these blocks of generated code! 
	//}}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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CDemoView construction/destruction 
 
CDemoView::CDemoView() 
{ 
	SetScrollSizes(MM_TEXT, CSize(0, 0)); 
 
} 
 
CDemoView::~CDemoView() 
{ 
} 
 
BOOL CDemoView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CScrollView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CDemoView drawing 
 
void CDemoView::OnDraw(CDC* pDC) 
{ 
	CDemoDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
 
	CPoint pos(GetScrollPosition()); 
	CRect rect; 
	GetClientRect(&rect); 
	int width = rect.right - rect.left; 
	int height = rect.bottom - rect.top; 
 
	if (pDoc->GetImage()) 
	{ 
		int x = -pos.x; 
		int y = -pos.y; 
		if (width >= pDoc->GetImage()->GetWidth()) 
			x = (width - pDoc->GetImage()->GetWidth())/2; 
		if (height >= pDoc->GetImage()->GetHeight()) 
			y = (height - pDoc->GetImage()->GetHeight())/2; 
 
		CDC *dc = GetDC(); 
		CPalette *hOldPal = 0; 
		if (pDoc->GetImage()->GetPalette()) 
		{ 
			hOldPal = dc->SelectPalette(pDoc->GetImage()->GetPalette(), TRUE); 
			dc->RealizePalette(); 
		} 
 
		if (pDoc->GetStretchMode()) 
		{ 
			SetScrollSizes(MM_TEXT, 
				CSize(0,0)); 
			pDoc->GetImage()->Stretch(dc, 0, 0, width, height); 
		} 
		else 
		{ 
			SetScrollSizes(MM_TEXT, 
				CSize(pDoc->GetImage()->GetWidth(), pDoc->GetImage()->GetHeight())); 
			pDoc->GetImage()->Draw(dc, x, y); 
		} 
 
//		dc->SelectPalette(hOldPal, TRUE); 
		ReleaseDC(dc); 
	} 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CDemoView printing 
 
BOOL CDemoView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CDemoView diagnostics 
 
#ifdef _DEBUG 
void CDemoView::AssertValid() const 
{ 
	CScrollView::AssertValid(); 
} 
 
void CDemoView::Dump(CDumpContext& dc) const 
{ 
	CScrollView::Dump(dc); 
} 
 
CDemoDoc* CDemoView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDemoDoc))); 
	return (CDemoDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CDemoView message handlers 
 
void CDemoView::OnInitialUpdate()  
{ 
	CScrollView::OnInitialUpdate(); 
	 
	if (GetDocument()->GetImage()) 
		SetScrollSizes(MM_TEXT, 
		  CSize(GetDocument()->GetImage()->GetWidth(), GetDocument()->GetImage()->GetHeight())); 
}