-
Notifications
You must be signed in to change notification settings - Fork 0
/
BMPMDLButton.cpp
157 lines (138 loc) · 3.41 KB
/
BMPMDLButton.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// BMPMDLButton.cpp : implementation file
//
#include "stdafx.h"
//#include "ICE.h"
#include "BMPMDLButton.h"
#include "..\AMT\MDLFile.h"
// CBMPMDLButton
IMPLEMENT_DYNAMIC(CBMPMDLButton, CBitmapButton)
CBMPMDLButton::CBMPMDLButton()
{
}
CBMPMDLButton::~CBMPMDLButton()
{
}
void CBMPMDLButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
if (m_bitmap.m_hObject == NULL)
{
CBrush br(RGB(0xFF,0,0));
pDC->FillRect(&lpDrawItemStruct->rcItem, &br);
pDC->TextOut(10,10,"NO BITMAP");
}
else
CBitmapButton::DrawItem(lpDrawItemStruct);
}
void CBMPMDLButton::LoadMDLFile(CString sMDLPath)
{
if (m_bitmap.m_hObject != NULL)
{
m_bitmap.DeleteObject();
}
CMDLFile mdlfile;
if (!mdlfile.ReadFromFile(sMDLPath))
{
CString res;
res.Format("Cant read file %s",sMDLPath);
//AfxMessageBox(res);
return;
}
if (!mdlfile.RootObject)
{
CString res;
res.Format("error invalid type, file %s",sMDLPath);
AfxMessageBox(res);
return;
}
if (mdlfile.RootObject->type != mdl_image)
{
CString res;
res.Format("error invalid type, file %s",sMDLPath);
AfxMessageBox(res);
return;
}
else
{
int width = mdlfile.RootObject->image->bw/2;
int height = mdlfile.RootObject->image->h;
m_bitmap.CreateBitmap(width,height,1,16,mdlfile.RootObject->image->bitmap);
/*
CRect rect,rectp;
GetParent()->GetWindowRect(&rectp);
GetWindowRect(&rect);
*/
//rect.SetRect(rect.left,rect.top,rect.left+width,rect.top+height);
//rect.NormalizeRect();
//MoveWindow(rectp.left-rect.left,rectp.top-rect.top,width,height,FALSE);
//CString res;
//res.Format("L=%d,T=%d,R=%d,B=%d",rect.left,rect.top,rect.right,rect.bottom);
//AfxMessageBox(res);
}
}
BEGIN_MESSAGE_MAP(CBMPMDLButton, CBitmapButton)
END_MESSAGE_MAP()
// CBMPMDLButton message handlers
/* old version
void CBMPMDLButton::LoadMDLFile(CString sMDLPath)
{
CFile fMDL;
if (m_bitmap.m_hObject != NULL)
{
m_bitmap.DeleteObject();
}
if (!fMDL.Open(sMDLPath,CFile::modeRead))
{
CString res;
res.Format("Cant read BMP.MDF file %s",sMDLPath);
//AfxMessageBox(res);
return;
}
bool bCont = true;
int cc = 0;
while (bCont)
{
BYTE c;
bCont = (fMDL.Read(&c,1) == 1);
if (c == 0xCC) cc++;
else cc=0;
if (cc == 3) bCont = false;
}
if (cc !=3)
{
CString res;
res.Format("invalid BMP.MDF file %s",sMDLPath);
AfxMessageBox(res);
}
else
{
ULONGLONG iCCPos = fMDL.Seek(0,CFile::current);
int width,height;
fMDL.Seek(iCCPos - 36,CFile::begin);
fMDL.Read(&width,sizeof(width));
fMDL.Read(&height,sizeof(height));
int lBmpScanWidth;
fMDL.Read(&lBmpScanWidth,sizeof(lBmpScanWidth));
int clBmpWidth = lBmpScanWidth / 2;
int clBmpHeight = height;
//CString res;
//res.Format("W=%d,H=%d,SW=%d,bmpsize=%d",width,height,lBmpScanWidth,clBmpWidth * clBmpHeight * 2);
//AfxMessageBox(res);
BYTE *lpBits = new BYTE[clBmpWidth * clBmpHeight * 2];
fMDL.Seek(iCCPos,CFile::begin);
fMDL.Read(lpBits,clBmpWidth * clBmpHeight * 2);
m_bitmap.CreateBitmap(width,height,1,16,lpBits);
delete lpBits;
CRect rect,rectp;
GetParent()->GetWindowRect(&rectp);
GetWindowRect(&rect);
//rect.SetRect(rect.left,rect.top,rect.left+width,rect.top+height);
//rect.NormalizeRect();
//MoveWindow(rectp.left-rect.left,rectp.top-rect.top,width,height,FALSE);
//CString res;
//res.Format("L=%d,T=%d,R=%d,B=%d",rect.left,rect.top,rect.right,rect.bottom);
//AfxMessageBox(res);
}
fMDL.Close();
}
*/