【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-ZOOMVIEW.CPP,希望本篇文章对您学习有所帮助。
// zoomview.cpp : Implements Zooming functions in a CScrollView window
//
// Written by Brad Pirtle, CS:72450,1156, Internet:pirtle@qlogic.com
// Copyright 1994, QuickLogic Corp., all rights reserved.
// Version 1.0
#include "stdafx.h"
#include "zoomview.h"
#include "resource.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CZoomView, CScrollView)
//{{AFX_MSG_MAP(CZoomView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#define MAXZOOMIN 4 // Maximum zoom-in factor
#define PICKMARGIN 10 // Screen pixels apart for region zoom
/////////////////////////////////////////////////////////////////////////////
// CZoomView
IMPLEMENT_DYNCREATE(CZoomView, CScrollView)
/*---------------------------------------------------------------------------
FUNCTION: CZoomView
PURPOSE : Constructor for the CZoomView class
---------------------------------------------------------------------------*/
CZoomView::CZoomView()
: CScrollView()
{
// Init zoom mode to nothing
m_zoomMode = MODE_ZOOMOFF;
m_bCaptured = FALSE;
m_zoomScale = 1.0;
m_ptDragRect.SetRectEmpty();
// Load the zoom cursor
m_hZoomCursor = ::LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_ZOOMCURSOR));
// Default to centering on full fit
m_bCenter = TRUE;
} // CZoomView
/*---------------------------------------------------------------------------
FUNCTION: ~CZoomView
PURPOSE : Destructor for the CZoomView class
---------------------------------------------------------------------------*/
CZoomView::~CZoomView()
{
// Clean up the cursors if they were loaded properly
if (m_hZoomCursor) DestroyCursor(m_hZoomCursor);
} // ~CZoomView
/////////////////////////////////////////////////////////////////////////////
// CZoomView overridden default CScrollView members
/////////////////////////////////////////////////////////////////////////////
/*---------------------------------------------------------------------------
FUNCTION: SetZoomSizes
PURPOSE : Set up the CZoomView class with the logical page size, and
scrolling page/line units.
This replaces CScrollView::SetScrollSizes.
---------------------------------------------------------------------------*/
void CZoomView::SetZoomSizes (
SIZE sizeTotal,
const SIZE& sizePage, // in logical units
const SIZE& sizeLine) // in logical units
{
// Set up the defaults
ASSERT(sizeTotal.cx >= 0 && sizeTotal.cy >= 0);
m_nMapMode = MM_ANISOTROPIC; // Need for arbitrary scaling
m_totalLog = sizeTotal;
// Setup default Viewport extent to be conversion of Window extent
// into device units.
//BLOCK for DC
{
CWindowDC dc(NULL);
dc.SetMapMode(m_nMapMode);
// total size
m_totalDev = m_totalLog;
dc.LPtoDP((LPPOINT)&m_totalDev);
} // Release DC here
// Save the origional Viewport Extent
m_origTotalDev = m_totalDev;
// Save the origional scrollbar info - for CalcBars
m_origPageDev = sizePage;
m_origLineDev = sizeLine;
// Fugure out scroll bar info
CalcBars();
// Notify the class that the zoom scale was set
NotifyZoom();
} // SetZoomSizes
/*---------------------------------------------------------------------------
FUNCTION: OnPrepareDC
PURPOSE : Override of CScrollView for MM_ANISOTROPIC zoom mode
---------------------------------------------------------------------------*/
void CZoomView::OnPrepareDC (
CDC* pDC,
CPrintInfo* pInfo)
{
#ifdef _DEBUG
if (m_nMapMode != MM_ANISOTROPIC) {
TRACE0("Error: must call SetZoomSizes() before painting zoom view\n");
ASSERT(FALSE);
return;
}
#endif //_DEBUG
ASSERT_VALID(pDC);
ASSERT(m_totalLog.cx >= 0 && m_totalLog.cy >= 0);
ASSERT(m_totalDev.cx >= 0 && m_totalDev.cx >= 0);
// Set the Mapping mode, and the window and viewport extents
pDC->SetMapMode(m_nMapMode);
pDC->SetWindowExt(m_totalLog); // in logical coordinates
CPoint ptVpOrg;
if (!pDC->IsPrinting()) {
pDC->SetViewportExt(m_totalDev); // in device coordinates
// by default shift viewport origin in negative direction of scroll
ASSERT(pDC->GetWindowOrg() == CPoint(0,0));
ptVpOrg = -GetDeviceScrollPosition();
// Center full fit
if (m_bCente