-
Notifications
You must be signed in to change notification settings - Fork 0
/
MDLView.cpp
137 lines (120 loc) · 2.78 KB
/
MDLView.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
// MDLView.cpp : implementation file
//
#include "stdafx.h"
#include "ICE.h"
#include "corestruct.h"
#include "BMPMDLButton.h"
#include "MDLView.h"
// CMDLView dialog
IMPLEMENT_DYNAMIC(CMDLView, CDialog)
CMDLView::CMDLView(CWnd* pParent /*=NULL*/)
: CDialog(CMDLView::IDD, pParent)
{
sArtPath = "";
sModel = "";
rawdata = NULL;
}
CMDLView::~CMDLView()
{
if (rawdata)
delete rawdata;
}
void CMDLView::DoDataExchange(CDataExchange* pDX)
{
CString todo1;
ASSERT(sArtPath != "");
if (!rawdata) return;
if (!pDX->m_bSaveAndValidate) // data to dialog
{
todo1.Format("%08x - ",0);
for (UINT i=0;i<rawsize;i++)
{
todo1.AppendFormat("%02X ",rawdata[i]);
if (!((i+1)%16)) todo1.AppendFormat("\r\n%08x - ",i+1);
}
}
DDX_Text(pDX, IDC_TODO1, todo1);
if (pDX->m_bSaveAndValidate) // dialog to data
{
}
CDialog::DoDataExchange(pDX);
}
BOOL CMDLView::OnInitDialog(void)
{
CDialog::OnInitDialog();
VERIFY(mdlbmp.SubclassDlgItem(IDC_PICT, this));
mdlbmp.LoadMDLFile(sArtPath+"\\"+sModel+"bmp.mdl");
CFile fMDL;
CString sMDL = sArtPath+"\\"+sModel+".mdl";
if (!fMDL.Open(sMDL,CFile::modeRead))
{
CString res;
res.Format("Cant read MDL file %s",sMDL);
AfxMessageBox(res);
}
else
{
rawsize = fMDL.GetLength();
rawdata = new UCHAR[rawsize];
fMDL.Read(rawdata,rawsize);
fMDL.Close();
UpdateData(FALSE);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BEGIN_MESSAGE_MAP(CMDLView, CDialog)
ON_BN_CLICKED(IDC_DECODEH, OnBnClickedDecodeh)
ON_BN_CLICKED(IDC_DECODESEL, OnBnClickedDecodesel)
END_MESSAGE_MAP()
// CMDLView message handlers
void CMDLView::OnBnClickedDecodeh()
{
CEdit *cetodo = (CEdit *) CWnd::GetDlgItem(IDC_TODO1);
int i,j;
cetodo->GetSel(i,j);
// NT SPECIFIC
HLOCAL h = cetodo->GetHandle();
LPCTSTR lpszText = (LPCTSTR)LocalLock(h);
char res[1000];
strncpy(res,&(lpszText[i]),j-i);
SetDlgItemText(IDC_DECDEC,res);
unsigned short f;
unsigned char *pf;
unsigned int b1,b2;
pf = (unsigned char *)&f;
sscanf(res,"%x %x",&b1,&b2);
pf[0] = b1;
pf[1] = b2;
CString sres;
sres.Format("%04X = %d",f,f);
SetDlgItemText(IDC_DECFLOAT,sres);
LocalUnlock(h);
// END OF NT SPECIFIC
}
void CMDLView::OnBnClickedDecodesel()
{
CEdit *cetodo = (CEdit *) CWnd::GetDlgItem(IDC_TODO1);
int i,j;
cetodo->GetSel(i,j);
// NT SPECIFIC
HLOCAL h = cetodo->GetHandle();
LPCTSTR lpszText = (LPCTSTR)LocalLock(h);
char res[1000];
strncpy(res,&(lpszText[i]),j-i);
SetDlgItemText(IDC_DECDEC,res);
float f;
unsigned char *pf;
unsigned int b1,b2,b3,b4;
pf = (unsigned char *)&f;
sscanf(res,"%x %x %x %x",&b1,&b2,&b3,&b4);
pf[0] = b1;
pf[1] = b2;
pf[2] = b3;
pf[3] = b4;
CString sres;
sres.Format("%g",f);
SetDlgItemText(IDC_DECFLOAT,sres);
LocalUnlock(h);
// END OF NT SPECIFIC
}