-
Notifications
You must be signed in to change notification settings - Fork 0
/
ENGINE.CPP
210 lines (178 loc) · 5.18 KB
/
ENGINE.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// engine.cpp : implementation of the Anode class
//
// Copyright (C) 1993-1994 George Mills and Softronics, Inc. Corporation
// All rights reserved.
//
#include "stdafx.h"
Anode::Anode(int state, char *name, int drivestate)
{
State = state;
NextState = state;
PrevState = state;
Name = name;
DriveState = drivestate;
NextDriveState = drivestate;
PrevDriveState = drivestate;
LastCycle = -1;
}
void Anode::Update()
{
PrevState = State;
State = NextState;
PrevDriveState = DriveState;
DriveState = NextDriveState;
}
AKeyboardMessage::AKeyboardMessage(CLogiGate* plogigate, CLogiView* pview, BOOL bdown, UINT nchar)
{
pLogiGate = plogigate;
pView = pview;
bDown = bdown;
nChar = nchar;
}
ANetworkMessage::ANetworkMessage(CLogiGate* plogigate, CLogiDoc* pdoc, LPARAM lparam, WPARAM wparam)
{
pLogiGate = plogigate;
pDoc = pdoc;
lParam = lparam;
wParam = wparam;
}
AMouseMessage::AMouseMessage(CLogiGate* plogigate, CLogiView* pview, BOOL bdown, CPoint &apoint)
{
pLogiGate = plogigate;
pView = pview;
bDown = bdown;
aPoint = apoint;
}
LPSTR GetShellExecuteError(int iError)
{
switch( iError )
{
case 0:
return "The operating system is out of memory or resources.";
case ERROR_FILE_NOT_FOUND:
return "The specified file was not found.";
case ERROR_PATH_NOT_FOUND:
return "The specified path was not found.";
case ERROR_BAD_FORMAT:
return "The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).";
case SE_ERR_ACCESSDENIED:
return "The operating system denied access to the specified file.";
case SE_ERR_ASSOCINCOMPLETE:
return "The filename association is incomplete or invalid.";
case SE_ERR_DDEBUSY:
return "The DDE transaction could not be completed because other DDE transactions were being processed.";
case SE_ERR_DDEFAIL:
return "The DDE transaction failed.";
case SE_ERR_DDETIMEOUT:
return "The DDE transaction could not be completed because the request timed out.";
case SE_ERR_DLLNOTFOUND:
return "The specified dynamic-link library was not found.";
// case SE_ERR_FNF:
// return "The specified file was not found.";
case SE_ERR_NOASSOC:
return "There is no application associated with the given filename extension.";
case SE_ERR_OOM:
return "There was not enough memory to complete the operation.";
// case SE_ERR_PNF:
// return "The specified path was not found.";
case SE_ERR_SHARE:
return "A sharing violation occurred.";
default:
return "Unknown reason.";
}
}
void LaunchFile(CString &csFile)
{
HINSTANCE hInstance = ShellExecute(AfxGetMainWnd()->GetSafeHwnd(), "open", csFile, NULL, NULL, SW_SHOWNORMAL);
if (intptr_t(hInstance) <= 32)
{
CString csMessage;
csMessage = GetShellExecuteError((int) intptr_t(hInstance));
csMessage += " ";
csMessage += csFile;
AfxMessageBox(csMessage);
}
}
void CheckWindow(int *x,int *y, int *w, int *h)
{
int MinX;
int MinY;
int MaxWidth;
int MaxHeight;
RECT MaxRect;
SystemParametersInfo(SPI_GETWORKAREA, 0, &MaxRect, 0);
MinX = MaxRect.left;
MinY = MaxRect.top;
MaxWidth = MaxRect.right - MaxRect.left + 1;
MaxHeight = MaxRect.bottom - MaxRect.top + 1;
// sanity check window coordinates
if (*x < MinX) *x = MinX;
if (*y < MinY) *y = MinY;
if (*w > MaxWidth) *w = MaxWidth;
if (*h > MaxHeight) *h = MaxHeight;
if ((*x+*w) > (MaxWidth+MinX)) *x = *x - (*x+*w-(MaxWidth+MinX));
if ((*y+*h) > (MaxHeight+MinY)) *y = *y - (*y+*h-(MaxHeight+MinY));
}
void RelativeToFullPath(CString &csRelPath, CString &csBasePath, CString &csFullPath)
{
char rdrive[_MAX_DRIVE];
char rdir[_MAX_DIR];
char rfname[_MAX_FNAME];
char rext[_MAX_EXT];
char bdrive[_MAX_DRIVE];
char bdir[_MAX_DIR];
char fpath[_MAX_PATH];
char *fdrive;
char *fdir;
_splitpath(csRelPath, rdrive, rdir, rfname, rext);
_splitpath(csBasePath, bdrive, bdir, NULL, NULL);
if (strlen(rdrive) == 0) fdrive = bdrive; else fdrive = rdrive;
if (strlen(rdir) == 0)
{
fdir = bdir;
}
else
{
if (rdir[0] == '\\')
{
fdir = rdir;
}
else
{
fdir = bdir;
strcat(fdir, rdir);
}
}
_makepath(fpath, fdrive, fdir, rfname, rext);
csFullPath = fpath;
}
BOOL TouchFile(CString &csFile)
{
FILE *pFile;
BOOL bStatus;
bStatus = TRUE;
pFile = fopen(csFile,"r");
if (pFile == NULL) pFile = fopen(csFile,"w");
// if ((csFile == "\\NUL") || (pFile == NULL))
// {
// CString csMsg;
// csMsg.Format("Cannot edit %s",csFile);
// ::MessageBox(::GetFocus(), csMsg, "Error", MB_OK);
// bStatus = FALSE;
// }
if (pFile != NULL) fclose(pFile);
return bStatus;
}
BOOL IsWindowsNT()
{
OSVERSIONINFO VersionInformation;
memset(&VersionInformation, 0, sizeof(OSVERSIONINFO));
VersionInformation.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&VersionInformation))
return VersionInformation.dwPlatformId == VER_PLATFORM_WIN32_NT;
else
{
ASSERT(FALSE);
return TRUE;
}
}