Repository navigation
Expand file tree
/
Copy pathbitmapobject.cpp
More file actions
89 lines (79 loc) · 1.86 KB
/
Copy pathbitmapobject.cpp
File metadata and controls
89 lines (79 loc) · 1.86 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// BitMapObject.cpp
#include "bitmapobject.h"
BitMapObject::BitMapObject()
{
hdcMemory = NULL;
hbmNewBitMap = NULL;
hbmOldBitMap = NULL;
iWidth = 0;
iHeight = 0;
}
BitMapObject::~BitMapObject()
{
// If the hdcMemory hasn't been destroyed then do so
if(hdcMemory)
Destroy();
}
void BitMapObject::Load(HDC hdcCompatible, LPCTSTR lpszFilename)
{
// If hdcMemory isn't null then make it null
if(hdcMemory)
Destroy();
// Create memory dc
hdcMemory = CreateCompatibleDC(hdcCompatible);
// Load the bitmap
hbmNewBitMap = (HBITMAP)LoadImage(NULL, lpszFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
// Shove the image into the dc
hbmOldBitMap = (HBITMAP)SelectObject(hdcMemory, hbmNewBitMap);
// Grab the bitmap's properties
BITMAP bmp;
GetObject(hbmNewBitMap, sizeof(BITMAP), (LPVOID)&bmp);
// Grab the width and height
iWidth = bmp.bmWidth;
iHeight = bmp.bmHeight;
}
void BitMapObject::Create(HDC hdcCompatible, int width, int height)
{
// If hdcMemory isn't null than make it null
if(hdcMemory)
Destroy();
// Create memory dc
hdcMemory = CreateCompatibleDC(hdcCompatible);
// Create the bitmap
hbmNewBitMap = CreateCompatibleBitmap(hdcCompatible, width, height);
// Shove the image into the dc
hbmOldBitMap = (HBITMAP)SelectObject(hdcMemory, hbmNewBitMap);
// Change the width and height
iWidth = width;
iHeight = height;
}
void BitMapObject::Destroy()
{
// Restore old bitmap
SelectObject(hdcMemory, hbmOldBitMap);
// Delete new bitmap
DeleteObject(hbmNewBitMap);
// Delete device context
DeleteDC(hdcMemory);
// Set members to 0/NULL
hdcMemory = NULL;
hbmNewBitMap = NULL;
hbmOldBitMap = NULL;
iWidth = 0;
iHeight = 0;
}
BitMapObject::operator HDC()
{
// Return the hdcMemory
return(hdcMemory);
}
int BitMapObject::GetWidth()
{
// Return the width
return(iWidth);
}
int BitMapObject::GetHeight()
{
// Return the height
return(iHeight);
}