-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRuntime.cpp
394 lines (344 loc) · 9.19 KB
/
Runtime.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#include "Common.h"
// DEBUGGER /////////////////////////////////////////////////////////////////
#if !defined(RUN_ONLY)
// Identifiers of items displayed in the debugger
enum
{
// Example
// -------
// DB_CURRENTSTRING,
// DB_CURRENTVALUE,
// DB_CURRENTCHECK,
// DB_CURRENTCOMBO
};
// Items displayed in the debugger
WORD DebugTree[]=
{
// Example
// -------
// DB_CURRENTSTRING|DB_EDITABLE,
// DB_CURRENTVALUE|DB_EDITABLE,
// DB_CURRENTCHECK,
// DB_CURRENTCOMBO,
// End of table (required)
DB_END
};
#endif // !defined(RUN_ONLY)
// -------------------
// GetRunObjectSurface
// -------------------
// Implement this function instead of DisplayRunObject if your extension
// supports ink effects and transitions. Note: you can support ink effects
// in DisplayRunObject too, but this is automatically done if you implement
// GetRunObjectSurface (MMF applies the ink effect to the surface).
//
// Note: do not forget to enable the function in the .def file
// if you remove the comments below.
/*
cSurface* WINAPI DLLExport GetRunObjectSurface(LPRDATA rdPtr)
{
return NULL;
}
*/
// -------------------------
// GetRunObjectCollisionMask
// -------------------------
// Implement this function if your extension supports fine collision mode (OEPREFS_FINECOLLISIONS),
// Or if it's a background object and you want Obstacle properties for this object.
//
// Should return NULL if the object is not transparent.
//
// Note: do not forget to enable the function in the .def file
// if you remove the comments below.
//
/*
LPSMASK WINAPI DLLExport GetRunObjectCollisionMask(LPRDATA rdPtr, LPARAM lParam)
{
// Typical example for active objects
// ----------------------------------
// Opaque? collide with box
if ( (rdPtr->rs.rsEffect & EFFECTFLAG_TRANSPARENT) == 0 ) // Note: only if your object has the OEPREFS_INKEFFECTS option
return NULL;
// Transparent? Create mask
LPSMASK pMask = rdPtr->m_pColMask;
if ( pMask == NULL )
{
if ( rdPtr->m_pSurface != NULL )
{
DWORD dwMaskSize = rdPtr->m_pSurface->CreateMask(NULL, lParam);
if ( dwMaskSize != 0 )
{
pMask = (LPSMASK)calloc(dwMaskSize, 1);
if ( pMask != NULL )
{
rdPtr->m_pSurface->CreateMask(pMask, lParam);
rdPtr->m_pColMask = pMask;
}
}
}
}
// Note: for active objects, lParam is always the same.
// For background objects (OEFLAG_BACKGROUND), lParam maybe be different if the user uses your object
// as obstacle and as platform. In this case, you should store 2 collision masks
// in your data: one if lParam is 0 and another one if lParam is different from 0.
return pMask;
}
*/
// ============================================================================
//
// START APP / END APP / START FRAME / END FRAME routines
//
// ============================================================================
// -------------------
// StartApp
// -------------------
// Called when the application starts or restarts.
// Useful for storing global data
//
void WINAPI DLLExport StartApp(mv _far *mV, CRunApp* pApp)
{
// Example
// -------
// Delete global data (if restarts application)
// CMyData* pData = (CMyData*)mV->mvGetExtUserData(pApp, hInstLib);
// if ( pData != NULL )
// {
// delete pData;
// mV->mvSetExtUserData(pApp, hInstLib, NULL);
// }
}
// -------------------
// EndApp
// -------------------
// Called when the application ends.
//
void WINAPI DLLExport EndApp(mv _far *mV, CRunApp* pApp)
{
// Example
// -------
// Delete global data
// CMyData* pData = (CMyData*)mV->mvGetExtUserData(pApp, hInstLib);
// if ( pData != NULL )
// {
// delete pData;
// mV->mvSetExtUserData(pApp, hInstLib, NULL);
// }
}
// -------------------
// StartFrame
// -------------------
// Called when the frame starts or restarts.
//
void WINAPI DLLExport StartFrame(mv _far *mV, DWORD dwReserved, int nFrameIndex)
{
}
// -------------------
// EndFrame
// -------------------
// Called when the frame ends.
//
void WINAPI DLLExport EndFrame(mv _far *mV, DWORD dwReserved, int nFrameIndex)
{
}
// ============================================================================
//
// TEXT ROUTINES (if OEFLAG_TEXT)
//
// ============================================================================
// -------------------
// GetRunObjectFont
// -------------------
// Return the font used by the object.
//
/*
// Note: do not forget to enable the functions in the .def file
// if you remove the comments below.
void WINAPI GetRunObjectFont(LPRDATA rdPtr, LOGFONT* pLf)
{
// Example
// -------
// GetObject(rdPtr->m_hFont, sizeof(LOGFONT), pLf);
}
// -------------------
// SetRunObjectFont
// -------------------
// Change the font used by the object.
//
void WINAPI SetRunObjectFont(LPRDATA rdPtr, LOGFONT* pLf, RECT* pRc)
{
// Example
// -------
// HFONT hFont = CreateFontIndirect(pLf);
// if ( hFont != NULL )
// {
// if (rdPtr->m_hFont!=0)
// DeleteObject(rdPtr->m_hFont);
// rdPtr->m_hFont = hFont;
// SendMessage(rdPtr->m_hWnd, WM_SETFONT, (WPARAM)rdPtr->m_hFont, FALSE);
// }
}
// ---------------------
// GetRunObjectTextColor
// ---------------------
// Return the text color of the object.
//
COLORREF WINAPI GetRunObjectTextColor(LPRDATA rdPtr)
{
// Example
// -------
return 0; // rdPtr->m_dwColor;
}
// ---------------------
// SetRunObjectTextColor
// ---------------------
// Change the text color of the object.
//
void WINAPI SetRunObjectTextColor(LPRDATA rdPtr, COLORREF rgb)
{
// Example
// -------
rdPtr->m_dwColor = rgb;
InvalidateRect(rdPtr->m_hWnd, NULL, TRUE);
}
*/
// ============================================================================
//
// WINDOWPROC (interception of messages sent to hMainWin and hEditWin)
//
// Do not forget to enable the WindowProc function in the .def file if you implement it
//
// ============================================================================
/*
// Get the pointer to the object's data from its window handle
// Note: the object's window must have been subclassed with a
// callRunTimeFunction(rdPtr, RFUNCTION_SUBCLASSWINDOW, 0, 0);
// See the documentation and the Simple Control example for more info.
//
LPRDATA GetRdPtr(HWND hwnd, LPRH rhPtr)
{
return (LPRDATA)GetProp(hwnd, (LPCSTR)rhPtr->rh4.rh4AtomRd);
}
// Called from the window proc of hMainWin and hEditWin.
// You can intercept the messages and/or tell the main proc to ignore them.
//
LRESULT CALLBACK DLLExport WindowProc(LPRH rhPtr, HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
LPRDATA rdPtr = NULL;
switch (nMsg) {
// Example
case WM_CTLCOLORSTATIC:
{
// Get the handle of the control
HWND hWndControl = (HWND)lParam;
// Get a pointer to the RUNDATA structure (see GetRdptr function above for more info)
rdPtr = GetRdPtr(hWndControl, rhPtr);
// Check if the rdPtr pointer is valid and points to an object created with this extension
if ( rdPtr == NULL || rdPtr->rHo.hoIdentifier != IDENTIFIER )
break;
// OK, intercept the message
HDC hDC = (HDC)wParam;
SetBkColor(hDC, rdPtr->backColor);
SetTextColor(hDC, rdPtr->fontColor);
rhPtr->rh4.rh4KpxReturn = (long)rdPtr->hBackBrush;
return REFLAG_MSGRETURNVALUE;
}
break;
}
return 0;
}
*/
// ============================================================================
//
// DEBUGGER ROUTINES
//
// ============================================================================
// -----------------
// GetDebugTree
// -----------------
// This routine returns the address of the debugger tree
//
LPWORD WINAPI DLLExport GetDebugTree(LPRDATA rdPtr)
{
#if !defined(RUN_ONLY)
return DebugTree;
#else
return NULL;
#endif // !defined(RUN_ONLY)
}
// -----------------
// GetDebugItem
// -----------------
// This routine returns the text of a given item.
//
void WINAPI DLLExport GetDebugItem(LPSTR pBuffer, LPRDATA rdPtr, int id)
{
#if !defined(RUN_ONLY)
// Example
// -------
/*
char temp[DB_BUFFERSIZE];
switch (id)
{
case DB_CURRENTSTRING:
LoadString(hInstLib, IDS_CURRENTSTRING, temp, DB_BUFFERSIZE);
wsprintf(pBuffer, temp, rdPtr->text);
break;
case DB_CURRENTVALUE:
LoadString(hInstLib, IDS_CURRENTVALUE, temp, DB_BUFFERSIZE);
wsprintf(pBuffer, temp, rdPtr->value);
break;
case DB_CURRENTCHECK:
LoadString(hInstLib, IDS_CURRENTCHECK, temp, DB_BUFFERSIZE);
if (rdPtr->check)
wsprintf(pBuffer, temp, "TRUE");
else
wsprintf(pBuffer, temp, "FALSE");
break;
case DB_CURRENTCOMBO:
LoadString(hInstLib, IDS_CURRENTCOMBO, temp, DB_BUFFERSIZE);
wsprintf(pBuffer, temp, rdPtr->combo);
break;
}
*/
#endif // !defined(RUN_ONLY)
}
// -----------------
// EditDebugItem
// -----------------
// This routine allows to edit editable items.
//
void WINAPI DLLExport EditDebugItem(LPRDATA rdPtr, int id)
{
#if !defined(RUN_ONLY)
// Example
// -------
/*
switch (id)
{
case DB_CURRENTSTRING:
{
EditDebugInfo dbi;
char buffer[256];
dbi.pText=buffer;
dbi.lText=TEXT_MAX;
dbi.pTitle=NULL;
strcpy(buffer, rdPtr->text);
long ret=callRunTimeFunction(rdPtr, RFUNCTION_EDITTEXT, 0, (LPARAM)&dbi);
if (ret)
strcpy(rdPtr->text, dbi.pText);
}
break;
case DB_CURRENTVALUE:
{
EditDebugInfo dbi;
dbi.value=rdPtr->value;
dbi.pTitle=NULL;
long ret=callRunTimeFunction(rdPtr, RFUNCTION_EDITINT, 0, (LPARAM)&dbi);
if (ret)
rdPtr->value=dbi.value;
}
break;
}
*/
#endif // !defined(RUN_ONLY)
}