wzdbtmap.cpp

来自「MFC扩展编程实例」· C++ 代码 · 共 57 行

CPP
57
字号
// WzdBtmap.cpp : implementation of the CWzdBitmap class
//

#include "stdafx.h"
#include "WzdBtmap.h"
#include "resource.h"

/////////////////////////////////////////////////////////////////////////////
// CWzdBitmap

IMPLEMENT_DYNAMIC(CWzdBitmap, CBitmap)


CWzdBitmap::CWzdBitmap()
{
}

CWzdBitmap::~CWzdBitmap()
{
}

CBitmap *CWzdBitmap::Stretch(int nWidth, int nHeight, int nMode)
{
	CDC dcTo,dcFrom,dcScreen;
	dcScreen.Attach(::GetDC(NULL));

	// create "from" device context and select the loaded bitmap into it
	dcFrom.CreateCompatibleDC(&dcScreen);
	dcFrom.SelectObject(this);

	// create a "to" device context select a memory bitmap into it
	dcTo.CreateCompatibleDC(&dcScreen);
	CBitmap *pBitmap=new CBitmap;
	pBitmap->CreateCompatibleBitmap(&dcScreen, nWidth, nHeight);
	dcTo.SelectObject(pBitmap);

	// get original bitmap size
	BITMAP bmInfo;
	GetObject(sizeof(bmInfo),&bmInfo);

	// set the stretching mode
	dcTo.SetStretchBltMode(nMode);
	
	// stretch loaded bitmap into memory bitmap
	dcTo.StretchBlt( 0, 0, nWidth, nHeight, 
				 &dcFrom, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight, SRCCOPY );

	// delete and release device contexts
	dcTo.DeleteDC();
	dcFrom.DeleteDC();
	::ReleaseDC(NULL, dcScreen.Detach());

	// it's up to the caller to delete this new bitmap
	return pBitmap;
	
}

⌨️ 快捷键说明

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