【VC开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VC开源代码-ZoomPartView.cpp的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
// ZoomPartView.cpp : implementation of the CZoomPartView class
//
#include "stdafx.h"
#include "ZoomPart.h"
#include "ZoomPartDoc.h"
#include "ZoomPartView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CZoomPartView
IMPLEMENT_DYNCREATE(CZoomPartView, CView)
BEGIN_MESSAGE_MAP(CZoomPartView, CView)
//{{AFX_MSG_MAP(CZoomPartView)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CZoomPartView construction/destruction
CZoomPartView::CZoomPartView()
{
// TODO: add construction code here
m_pdcMem = new CDC;
m_pBitmap = new CBitmap;
recover = true;
s = 30; d = 45;
mana = SRCCOPY;
}
CZoomPartView::~CZoomPartView()
{
delete m_pdcMem;
delete m_pBitmap;
}
BOOL CZoomPartView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CZoomPartView drawing
void CZoomPartView::OnDraw(CDC* pDC)
{
CZoomPartDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//声明判断是否load位图的静态标志
static bool load;
//按原来大小显示位图
if (!load) {
BITMAP bm;
load = !load;
m_pBitmap->LoadBitmap(IDB_BITMAP1);
m_pdcMem->CreateCompatibleDC(pDC);
m_pdcMem->SelectObject(m_pBitmap);
m_pBitmap->GetObject(sizeof(bm),&bm);
m_sizeSource.cx = bm.bmWidth;
m_sizeSource.cy = bm.bmHeight;
m_sizeDest = m_sizeSource;
pDC->StretchBlt(0,0,m_sizeSource.cx,m_sizeSource.cy,
m_pdcMem,0,0,m_sizeSource.cx,m_sizeSource.cy,mana);
}
else {
pDC->StretchBlt(0,0,m_sizeSource.cx,m_sizeSource.cy,
m_pdcMem,0,0,m_sizeSource.cx,m_sizeSource.cy,mana);
}
}
/////////////////////////////////////////////////////////////////////////////
// CZoomPartView printing
BOOL CZoomPartView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CZoomPartView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CZoomPartView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CZoomPartView diagnostics
#ifdef _DEBUG
void CZoomPartView::AssertValid() const
{
CView::AssertValid();
}
void CZoomPartView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CZoomPartDoc* CZoomPartView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CZoomPartDoc)));
return (CZoomPartDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CZoomPartView message handlers
void CZoomPartView::OnMouseMove(UINT nFlags, CPoint point)
{
//计算要放大的局部矩形的源图像位置和目标位置
CString cord;
int dd;
CRect srect,drect,mrect;
srect.left = point.x - s;
srect.top = point.y - s;
srect.right = point.x + s;
srect.bottom = point.y + s;
drect.left = point.x - d;
drect.top = point.y - d;
drect.right = point.x + d;
drect.bottom = point.y + d;
mrect.left = oldx - d;
mrect.top = oldy - d;
mrect.right = oldx + d;
mrect.bottom = oldy + d;
dd = 2*d;
CDC * pDC = GetDC();
OnPrepareDC(pDC);
//放大图像
if (recover)
{
pDC->BitBlt(mrect.left,mrect.top,dd,dd,
m_pdcMem,mrect.left,mrect.top,mana);
}
pDC->StretchBlt(drect.left,drect.top,
drect.Width(),drect.Height(),m_pdcMem,srect.left,
srect.top,srect.Width(),srect.Height(),SRCCOPY);
oldx = point.x; oldy = point.y;
ReleaseDC(pDC);
recover = true;
CView::OnMouseMove(nFlags,