📄 maskedbitmap.cpp
字号:
//
// maskedBitmap.cpp
//
#include "stdafx.h"
#include "maskedBitmap.h"
/////////////////////////////////////////////////////////////////////////
// CMaskedBitmap member functions
void CMaskedBitmap::Draw (CDC* pDC, int x, int y)
{
BITMAP bm; // Allocate a bitmap (descriptor) structure on the stack
GetObject (sizeof (BITMAP), &bm); // ...and fill it in.
CPoint size (bm.bmWidth, bm.bmHeight); // Init a CPoint object to the size (width/height) of bm
pDC->DPtoLP (&size); // ...and convert to logical units (because that's what BitBlt takes).
CPoint org (0, 0); // Do the same for a point that's at the origin.
pDC->DPtoLP (&org);
CDC dcMem; // Construct a memory-based device context object.
dcMem.CreateCompatibleDC (pDC); //
CBitmap* pOldBitmap = dcMem.SelectObject (this); // "Selects the MaskedBitmap that we're drawing (this) into the device context."
// which means that SelectObject returns a pointer to the bitmap.
dcMem.SetMapMode (pDC->GetMapMode ()); // Copy pDC's MapMode into dcMem.
pDC->BitBlt // Dest: display context object
(x, y, // Dest: location of upper left corner in destination DC (in Logical units).
size.x, size.y, // Dest: size of the destination rectangle and source bitmap (in Logical units).
&dcMem, // Source bitmap - a pointer to a CDC object that identifies the device context of the source.
// It must be NULL if dwRop specifies a raster operation that does not include a source.
org.x, org.y, // Source: upper-left corner of the source bitmap (in Logical units).
SRCCOPY); // dwRop
// m_bitmapBackColor = pDC->GetPixel( x + 2, y + 2 ); // Get the background color (not quite at the edge of the bitmap).
dcMem.SelectObject (pOldBitmap);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -