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

📄 testbitmapview.cpp

📁 Visual c++.程序设计培训教程
💻 CPP
字号:
// TestBitmapView.cpp : implementation of the CTestBitmapView class
//

#include "stdafx.h"
#include "TestBitmap.h"

#include "TestBitmapDoc.h"
#include "TestBitmapView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView

IMPLEMENT_DYNCREATE(CTestBitmapView, CView)

BEGIN_MESSAGE_MAP(CTestBitmapView, CView)
	//{{AFX_MSG_MAP(CTestBitmapView)
		// 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()

/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView construction/destruction

CTestBitmapView::CTestBitmapView()
{
	// TODO: add construction code here

}

CTestBitmapView::~CTestBitmapView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView drawing

void CTestBitmapView::OnDraw(CDC* pDC)
{
	CTestBitmapDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	/////////////////////////////////////////////////////
	// 从资源中装入位图
	{
		//第一步:声明一个CBitmap对象,并从资源中装入位图
		CBitmap bitmap;
//		bitmap.LoadBitmap(IDB_BITMAP1);
		HBITMAP hbitmap = (HBITMAP)LoadImage( // 此函数可以从文件中装载一幅位图
			NULL,				// 如果从资源装载,则指明包含位图资源的程序实例句柄
			"fighter.bmp",		// 位图文件的名字或者位图资源的ID
			IMAGE_BITMAP,		// 装载的图像类型为位图
			0,0,				// 宽度和高度,0表示使用缺省值
			LR_LOADFROMFILE);	// 装载标志,表明从文件装载
 
		bitmap.Attach(hbitmap);

		//第二步:创建一个兼容DC
		CDC dcComp;
		dcComp.CreateCompatibleDC(pDC);
		//第三步:将位图选入兼容DC中
		dcComp.SelectObject(&bitmap);

		BITMAP bmInfo;
		bitmap.GetObject(sizeof(bmInfo),&bmInfo);

		//第四步:使用BitBlt函数显示位图
/*		pDC->BitBlt(0,0,                    //显示位置
			bmInfo.bmWidth,bmInfo.bmHeight, //显示位图的宽度和高度
			&dcComp,                        //位图所在的兼容DC
			0,0,                            //兼容DC中的位置
			SRCCOPY);                       //显示方式
*/
		CRect  rect;
		GetClientRect(rect);        // 获取视图窗口客户区大小

		pDC->StretchBlt(0,0,                 // 显示位置
			rect.Width(), rect.Height(),     // 显示的宽度和高度
			&dcComp,                         // 位图所在的兼容DC
			0,0,                             // 兼容DC中的位置
			bmInfo.bmWidth, bmInfo.bmHeight, // 位图的宽度和高度
			SRCCOPY);                        // 显示方式
	}

}

/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView message handlers

⌨️ 快捷键说明

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