ddbitmap.cpp
来自「API经典入门」· C++ 代码 · 共 78 行
CPP
78 行
// Filename: DDBitmap.cpp
#include "stdafx.h"
#include "DDBitmap.h"
// Constructors & Destructors
CDDBitmap::CDDBitmap()
{
// Place any one-time construction code here.
}
CDDBitmap::~CDDBitmap()
{
// Place any destruction code here (i.e. clean-up).
}
// Operations
BOOL CDDBitmap::DrawOnDC (CDC* pDC, int x, int y)
{
// Note: this function should really call
// the StretchOnDC() function so as to minimize
// code duplication. However, implementing this
// second method demonstrates the BitBlt()
// function of the CDC class.
// make sure the CDC pointer is usable
ASSERT_VALID(pDC);
// get bitmap info
BITMAP bm;
GetObject(sizeof(bm), &bm);
// create bitmap memory context
CDC dcBM;
dcBM.CreateCompatibleDC(pDC);
// select the bitmap into the DC
CBitmap* pOldBM = dcBM.SelectObject(this);
// block transfer the bitmap onto the screen
BOOL Result = pDC->BitBlt(x, y, bm.bmWidth,
bm.bmHeight, &dcBM, 0, 0, SRCCOPY);
// return the DC to its original state
dcBM.SelectObject(pOldBM);
return Result;
}
BOOL CDDBitmap::StretchOnDC (CDC* pDC,
int x, int y, int newWidth, int newHeight)
{
// make sure the CDC pointer is usable
ASSERT_VALID(pDC);
// get bitmap info
BITMAP bm;
GetObject(sizeof(bm), &bm);
// create bitmap memory context
CDC dcBM;
dcBM.CreateCompatibleDC(pDC);
// select the bitmap into the DC
CBitmap* pOldBM = dcBM.SelectObject(this);
// stretch the bitmap onto the screen
BOOL Result = pDC->StretchBlt(x, y,
newWidth, newHeight, &dcBM, 0, 0,
bm.bmWidth, bm.bmHeight, SRCCOPY);
// return the DC to its original state
dcBM.SelectObject(pOldBM);
return Result;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?