⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bmpdemo2view.cpp

📁 vc++程序设计与技巧中第8章“图形图像编程”部分的VC++原代码
💻 CPP
字号:
// BMPDemo2View.cpp : implementation of the CBMPDemo2View class
//

#include "stdafx.h"
#include "BMPDemo2.h"

#include "BMPDemo2Doc.h"
#include "BMPDemo2View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBMPDemo2View

IMPLEMENT_DYNCREATE(CBMPDemo2View, CView)

BEGIN_MESSAGE_MAP(CBMPDemo2View, CView)
	//{{AFX_MSG_MAP(CBMPDemo2View)
		// 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, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBMPDemo2View construction/destruction

CBMPDemo2View::CBMPDemo2View()
{
	// TODO: add construction code here
	m_Bitmap.LoadBitmap(IDB_BITMAP1);
}

CBMPDemo2View::~CBMPDemo2View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CBMPDemo2View drawing

void CBMPDemo2View::OnDraw(CDC* pDC)
{
	CBMPDemo2Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	int nWidth, nHeight;
	CDC *pMemDC = new CDC;
	//建立与显示设备兼容的内存设备场境
	pMemDC->CreateCompatibleDC(pDC);
	
	//获取位图尺寸
	BITMAP bm;
	m_Bitmap.GetBitmap(&bm);
	nWidth = bm.bmWidth;
	nHeight = bm.bmHeight;
	
	//将位图选入内存场境
	CBitmap *m_pBitmap = (CBitmap *) pMemDC->SelectObject(&m_Bitmap);
	//显示位图
	pDC->BitBlt(40,40,nWidth,nHeight,pMemDC,0,0,SRCCOPY);
	//对位图作伸缩处理
	pDC->StretchBlt(200,40,nWidth+80,nHeight+30,pMemDC,0,0,nWidth,nHeight,SRCCOPY);
	pDC->TextOut(220,40+nHeight+32,"伸缩效果");
	//对位图进行镜像处理
	pDC->StretchBlt(40+nWidth+20 , 40, nWidth, nHeight, pMemDC, 
		nWidth-1, 0, -nWidth, nHeight, SRCCOPY );
	pDC->TextOut(40+nWidth+20, 40+nHeight+3, "Y轴镜像");
	pDC->StretchBlt(40, 40+nHeight+20, nWidth, nHeight, pMemDC, 
		0, nHeight-1, nWidth, -nHeight, SRCCOPY );
	pDC->TextOut(40, 40+2*nHeight+20, "X轴镜像");
	
	
	delete pMemDC;
}

/////////////////////////////////////////////////////////////////////////////
// CBMPDemo2View printing

BOOL CBMPDemo2View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CBMPDemo2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

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

/////////////////////////////////////////////////////////////////////////////
// CBMPDemo2View diagnostics

#ifdef _DEBUG
void CBMPDemo2View::AssertValid() const
{
	CView::AssertValid();
}

void CBMPDemo2View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CBMPDemo2View message handlers

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -