www.pudn.com > PtBarcodeDec.rar > SampleView.cpp
// SampleView.cpp : implementation of the CSampleView class
//
#include "stdafx.h"
#include "Sample.h"
#include "SampleDoc.h"
#include "SampleView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSampleView
IMPLEMENT_DYNCREATE(CSampleView, CScrollView)
BEGIN_MESSAGE_MAP(CSampleView, CScrollView)
//{{AFX_MSG_MAP(CSampleView)
ON_COMMAND(ID_VIEW_ZOOM_LESS, OnViewZoomLess)
ON_COMMAND(ID_VIEW_ZOOM_MORE, OnViewZoomMore)
ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOM_LESS, OnUpdateViewZoomLess)
ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOM_MORE, OnUpdateViewZoomMore)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CSampleView construction/destruction
CSampleView::CSampleView()
{
// TODO: add construction code here
}
CSampleView::~CSampleView()
{
}
BOOL CSampleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSampleView drawing
void CSampleView::OnDraw(CDC* pDC)
{
CSampleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(pDoc->m_image.pBits==NULL)
return;
PtShowImage( &pDoc->m_image, pDC->GetSafeHdc() , 50, 50, pDoc->m_scale );
CSize sizeTotal( int(1.2*pDoc->m_scale*pDoc->m_image.dwWidth), int(1.2*pDoc->m_scale*pDoc->m_image.dwHeight) );
CSize sizePage(sizeTotal.cx/2, sizeTotal.cy/2);
CSize sizeLine(sizeTotal.cx/10, sizeTotal.cy/10);
SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
// TODO: add draw code for native data here
}
void CSampleView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CSampleView printing
BOOL CSampleView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSampleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSampleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSampleView diagnostics
#ifdef _DEBUG
void CSampleView::AssertValid() const
{
CScrollView::AssertValid();
}
void CSampleView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CSampleDoc* CSampleView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSampleDoc)));
return (CSampleDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSampleView message handlers
void CSampleView::OnViewZoomLess()
{
// TODO: Add your command handler code here
CSampleDoc* pDoc = GetDocument();
pDoc->m_scale*=(2.0f/3.0f);
Invalidate();
}
void CSampleView::OnViewZoomMore()
{
// TODO: Add your command handler code here
CSampleDoc* pDoc = GetDocument();
pDoc->m_scale*=(3.0f/2.0f);
Invalidate();
}
void CSampleView::OnUpdateViewZoomLess(CCmdUI* pCmdUI)
{
CSampleDoc* pDoc = GetDocument();
if(pDoc->m_image.pBits)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);// TODO: Add your command update UI handler code here
}
void CSampleView::OnUpdateViewZoomMore(CCmdUI* pCmdUI)
{
CSampleDoc* pDoc = GetDocument();
if(pDoc->m_image.pBits)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);// TODO: Add your command update UI handler code here
}