-
Notifications
You must be signed in to change notification settings - Fork 2
/
DrawHelper.cpp
44 lines (38 loc) · 1.04 KB
/
DrawHelper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "stdafx.h"
#include "DrawHelper.h"
CSCIDrawHelper::CSCIDrawHelper(CDC *pdc, BYTE *pData, const CSize &size)
{
_pBits = NULL;
_hDib = NULL;
_pData = NULL;
_size = size;
_hgdiObjOld = NULL;
if (dc.CreateCompatibleDC(pdc))
{
SCIBitmapInfo bmi(size.cx, size.cy);
_hDib = CreateDIBSection((HDC)dc, &bmi, DIB_RGB_COLORS, &_pBits, NULL, 0);
if (_hDib)
{
// Select our new HBITMAP into the DC
_hgdiObjOld = SelectObject((HDC)dc, _hDib);
// Copy memory from the view data into our temporary bits
_pData = pData;
CopyMemory(_pBits, _pData, CX_ACTUAL(size.cx) * size.cy);
}
}
}
CSCIDrawHelper::~CSCIDrawHelper()
{
// Select back the original object.
dc.SelectObject(_hgdiObjOld);
// Copy memory back into the view data.
if (_pData && _pBits)
{
CopyMemory(_pData, _pBits, CX_ACTUAL(_size.cx) * _size.cy);
}
// Finally delete our DIB
if (_hDib)
{
DeleteObject(_hDib);
}
}