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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
/************************************************************/
/* Windows Write, Copyright 1985-1992 Microsoft Corporation */
/************************************************************/
/* register.c - Handles the Win 3.1 registration library.
*
* Created by Microsoft Corporation.
*/
#define LSTRING // for lstrcat etc
#include <windows.h>
#include <shellapi.h>
#include "objreg.h"
#include "mw.h"
#include "winddefs.h"
#include "obj.h"
#include "str.h" /* Needed for string resource id */
#include "menudefs.h"
#include "cmddefs.h"
char szClassName[CBPATHMAX];
HKEY hkeyRoot = NULL;
void NEAR PASCAL MakeMenuString(char *szCtrl, char *szMenuStr, char *szVerb, char *szClass, char *szObject);
/* RegInit() - Prepare the registration database for calls.
*/
void FAR RegInit(HANDLE hInst)
{
/* this seems to speed up registration operations immensely, but serves
no other purpose */
//RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkeyRoot);
}
/* RegTerm() - Clean up and terminate the registration library.
*/
void FAR RegTerm(void)
{
if (hkeyRoot)
{
RegCloseKey(hkeyRoot);
hkeyRoot = NULL;
}
}
/* RegGetClassId() - Retrieves the string name of a class.
*
* Note: Classes are guaranteed to be in ASCII, but should
* not be used directly as a rule because they might
* be meaningless if running non-English Windows.
*/
void FAR RegGetClassId(LPSTR lpstrName, LPSTR lpstrClass) {
DWORD dwSize = KEYNAMESIZE;
if (RegQueryValue(HKEY_CLASSES_ROOT, lpstrClass, (LPSTR)lpstrName, &dwSize))
lstrcpy(lpstrName, lpstrClass);
}
/* RegMakeFilterSpec() - Retrieves class-associated default extensions.
*
* This function returns a filter spec, to be used in the "Change Link"
* standard dialog box, which contains all the default extensions which
* are associated with the given class name. Again, the class names are
* guaranteed to be in ASCII.
*
* Returns: The index nFilterIndex stating which filter item matches the
* extension, or 0 if none is found or -1 if error.
** *hFilterSpec is allocated and must be freed by caller.
*/
int FAR RegMakeFilterSpec(LPSTR lpstrClass, LPSTR lpstrExt, HANDLE *hFilterSpec)
{
DWORD dwSize;
LPSTR lpstrFilterSpec;
char szClass[KEYNAMESIZE];
char szName[KEYNAMESIZE];
char szString[KEYNAMESIZE];
unsigned int i;
int idWhich = 0;
int idFilterIndex = 0;
if (*hFilterSpec == NULL)
{
if ((*hFilterSpec = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,KEYNAMESIZE+16)) == NULL)
return -1;
lpstrFilterSpec = MAKELP(*hFilterSpec,0);
}
RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkeyRoot);
for (i = 0; !RegEnumKey(HKEY_CLASSES_ROOT, i++, szName, KEYNAMESIZE); )
{
if (*szName == '.' /* Default Extension... */
/* ... so, get the class name */
&& (dwSize = KEYNAMESIZE)
&& !RegQueryValue(HKEY_CLASSES_ROOT, szName, szClass, &dwSize)
/* ... and if the class name matches (null class is wildcard) */
&& (!lpstrClass || !lstrcmpi(lpstrClass, szClass))
/* ... get the class name string */
&& (dwSize = KEYNAMESIZE)
&& !RegQueryValue(HKEY_CLASSES_ROOT, szClass, szString, &dwSize))
{
int offset;
idWhich++;
/* If the extension matches, save the filter index */
if (lpstrExt && !lstrcmpi(lpstrExt, szName))
idFilterIndex = idWhich;
offset = lpstrFilterSpec - MAKELP(*hFilterSpec,0);
if ((GlobalSize(*hFilterSpec) - offset) <
(lstrlen(szString) + 16))
{
if ((*hFilterSpec = GlobalReAlloc(*hFilterSpec,GlobalSize(*hFilterSpec)+KEYNAMESIZE+16,
GMEM_MOVEABLE|GMEM_ZEROINIT)) == NULL)
{
GlobalFree(*hFilterSpec);
*hFilterSpec = NULL;
idFilterIndex = -1;
break;
}
lpstrFilterSpec = (LPSTR)MAKELP(*hFilterSpec,0) + offset;
}
/* Copy over "<Class Name String> (*<Default Extension>)"
* e.g. "Server Picture (*.PIC)"
*/
lstrcpy(lpstrFilterSpec, szString);
lstrcat(lpstrFilterSpec, " (*");
lstrcat(lpstrFilterSpec, szName);
lstrcat(lpstrFilterSpec, ")");
lpstrFilterSpec += lstrlen(lpstrFilterSpec) + 1;
/* Copy over "*<Default Extension>" (e.g. "*.PIC") */
lstrcpy(lpstrFilterSpec, "*");
lstrcat(lpstrFilterSpec, szName);
lpstrFilterSpec += lstrlen(lpstrFilterSpec) + 1;
}
}
/* Add another NULL at the end of the spec (+ 16 accounts for this) */
if (idFilterIndex > -1)
*lpstrFilterSpec = 0;
if (hkeyRoot)
{
RegCloseKey(hkeyRoot);
hkeyRoot = NULL;
}
return idFilterIndex;
}
/* RegCopyClassName() - Returns the ASCII class id from the listbox.
*/
BOOL FAR RegCopyClassName(HWND hwndList, LPSTR lpstrClassName) {
BOOL fSuccess = FALSE;
DWORD dwSize = 0L;
HKEY hkeyTemp;
char szClass[KEYNAMESIZE];
char szExec[KEYNAMESIZE];
char szKey[KEYNAMESIZE];
char szName[KEYNAMESIZE];
int i;
int iWhich;
iWhich = (int)SendMessage(hwndList, LB_GETCURSEL, 0, 0L);
SendMessage(hwndList, LB_GETTEXT, iWhich, (DWORD)(LPSTR)szKey);
RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkeyRoot);
for (i = 0; !fSuccess && !RegEnumKey(HKEY_CLASSES_ROOT, i++, szClass, KEYNAMESIZE); )
if (*szClass != '.') { /* Not default extension... */
/* See if this class really refers to a server */
dwSize = 0;
hkeyTemp = NULL;
lstrcpy(szExec, szClass);
lstrcat(szExec, "\\protocol\\StdFileEditing\\server");
if (!RegOpenKey(HKEY_CLASSES_ROOT, szExec, &hkeyTemp)) {
/* ... get the class name string */
dwSize = KEYNAMESIZE;
if (!RegQueryValue(HKEY_CLASSES_ROOT, szClass, szName, &dwSize)
&& !lstrcmp(szName, szKey))
fSuccess = TRUE;
RegCloseKey(hkeyTemp);
}
}
if (fSuccess)
lstrcpy(lpstrClassName, szClass);
if (hkeyRoot)
{
RegCloseKey(hkeyRoot);
hkeyRoot = NULL;
}
return fSuccess;
}
/* RegGetClassNames() - Fills the list box with possible server names.
*/
BOOL FAR RegGetClassNames(HWND hwndList) {
BOOL fSuccess = FALSE;
DWORD dwSize = 0L;
HKEY hkeyTemp;
char szClass[KEYNAMESIZE];
char szExec[KEYNAMESIZE];
char szName[KEYNAMESIZE];
int i;
SendMessage(hwndList, LB_RESETCONTENT, 0, 0L);
RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkeyRoot);
for (i = 0; !RegEnumKey(HKEY_CLASSES_ROOT, i++, szClass, KEYNAMESIZE); )
if (*szClass != '.') { /* Not default extension... */
/* See if this class really refers to a server */
dwSize = 0;
hkeyTemp = NULL;
lstrcpy(szExec, szClass);
lstrcat(szExec, "\\protocol\\StdFileEditing\\server");
if (!RegOpenKey(HKEY_CLASSES_ROOT, szExec, &hkeyTemp)) {
/* ... get the class name string */
dwSize = KEYNAMESIZE;
if (!RegQueryValue(HKEY_CLASSES_ROOT, szClass, szName, &dwSize)) {
SendMessage(hwndList, LB_ADDSTRING, 0, (DWORD)(LPSTR)szName);
fSuccess = TRUE;
}
RegCloseKey(hkeyTemp);
}
}
if (hkeyRoot)
{
RegCloseKey(hkeyRoot);
hkeyRoot = NULL;
}
return fSuccess;
}
void ObjUpdateMenuVerbs( HMENU hMenu )
{
int cObjects;
extern struct SEL selCur;
extern char szOPropMenuStr[];
extern char szPPropMenuStr[];
extern BOOL vfOutOfMemory;
char szBuffer[cchMaxSz];
char szWordOrder2[10], szWordOrder3[10];
if (vfOutOfMemory)
{
EnableMenuItem(hMenu, EDITMENUPOS, MF_GRAYED|MF_BYPOSITION);
return;
}
LoadString(hINSTANCE, IDSTRPopupVerbs, szWordOrder2, sizeof(szWordOrder2));
LoadString(hINSTANCE, IDSTRSingleVerb, szWordOrder3, sizeof(szWordOrder3));
DeleteMenu(hMenu, EDITMENUPOS, MF_BYPOSITION);
/** Cases:
0) 0 objects selected
1) 1 object selected
a) object supports 0 verbs "Edit <Object Class> Object"
b) object supports more than 1 verb "<Object Class> Object" => verbs
2) more than 1 object selected "Objects"
Use the VerbMenu strings to determine the order in which these words
should appear in the menu string (for localization).
**/
/* how many objects are selected? */
cObjects = ObjSetSelectionType(docCur,selCur.cpFirst, selCur.cpLim);
/* must be only an object, not text in selection */
if (cObjects == 1)
{
ObjCachePara(docCur,selCur.cpFirst);
if (!ObjQueryCpIsObject(docCur,selCur.cpFirst))
cObjects = 0;
}
if ((cObjects == -1) // error
|| (cObjects == 0)
|| (cObjects > 1))
{
wsprintf(szBuffer, "%s", (LPSTR)((cObjects > 1) ? szPPropMenuStr : szOPropMenuStr));
InsertMenu(hMenu, EDITMENUPOS, MF_BYPOSITION,imiVerb,szBuffer);
/*
Spec says if > 1 then optionally should enable if all servers
are of the same class. I'm opting not to implement. (9.27.91) v-dougk
*/
EnableMenuItem(hMenu, EDITMENUPOS, MF_GRAYED | MF_BYPOSITION);
#if 0
else // > 1
{
EnableMenuItem(hMenu, EDITMENUPOS,
(((OBJ_SELECTIONTYPE == EMBEDDED) || (OBJ_SELECTIONTYPE == LINK))
? MF_ENABLED : MF_GRAYED) | MF_BYPOSITION);
}
#endif
return;
}
else // 1 object selected
{
OBJPICINFO picInfo;
/** CASES:
object supports 0 verbs "Edit <Object Class> Object"
object supports more than 1 verb "<Object Class> Object" => verbs
**/
RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkeyRoot);
GetPicInfo(selCur.cpFirst,selCur.cpFirst + cchPICINFOX, docCur, &picInfo);
if ((otOBJ_QUERY_TYPE(&picInfo) == EMBEDDED) ||
(otOBJ_QUERY_TYPE(&picInfo) == LINK))
{
HANDLE hData=NULL;
LPSTR lpstrData;
OLESTATUS olestat;
olestat = OleGetData(lpOBJ_QUERY_OBJECT(&picInfo),
otOBJ_QUERY_TYPE(&picInfo) == LINK? vcfLink: vcfOwnerLink,
&hData);
if ((olestat == OLE_WARN_DELETE_DATA) || (olestat == OLE_OK))
{
HKEY hKeyVerb;
DWORD dwSize = KEYNAMESIZE;
char szClass[KEYNAMESIZE];
char szVerb[KEYNAMESIZE];
HANDLE hPopupNew=NULL;
lpstrData = MAKELP(hData,0);
/* Both link formats are: "szClass0szDocument0szItem00" */
/* get real language class of object in szClass for menu */
if (RegQueryValue(HKEY_CLASSES_ROOT, lpstrData, szClass, &dwSize))
lstrcpy(szClass, lpstrData); /* if above call failed */
if (olestat == OLE_WARN_DELETE_DATA)
GlobalFree(hData);
/* append class key */
for (vcVerbs=0; ;++vcVerbs)
{
dwSize = KEYNAMESIZE;
wsprintf(szBuffer, "%s\\protocol\\StdFileEditing\\verb\\%d", (LPSTR)lpstrData,vcVerbs);
if (RegQueryValue(HKEY_CLASSES_ROOT, szBuffer, szVerb, &dwSize))
break;
if (hPopupNew == NULL)
hPopupNew = CreatePopupMenu();
InsertMenu(hPopupNew, -1, MF_BYPOSITION, imiVerb+vcVerbs+1, szVerb);
}
if (vcVerbs == 0)
{
LoadString(hINSTANCE, IDSTREdit, szVerb, sizeof(szVerb));
MakeMenuString(szWordOrder3, szBuffer, szVerb, szClass, szOPropMenuStr);
InsertMenu(hMenu, EDITMENUPOS, MF_BYPOSITION, imiVerbPlay, szBuffer);
}
else if (vcVerbs == 1)
{
MakeMenuString(szWordOrder3, szBuffer, szVerb, szClass, szOPropMenuStr);
InsertMenu(hMenu, EDITMENUPOS, MF_BYPOSITION, imiVerbPlay, szBuffer);
DestroyMenu(hPopupNew);
}
else // > 1 verbs
{
MakeMenuString(szWordOrder2, szBuffer, NULL, szClass, szOPropMenuStr);
InsertMenu(hMenu, EDITMENUPOS, MF_BYPOSITION | MF_POPUP,
hPopupNew, szBuffer);
}
EnableMenuItem(hMenu, EDITMENUPOS, MF_ENABLED|MF_BYPOSITION);
if (hkeyRoot)
{
RegCloseKey(hkeyRoot);
hkeyRoot = NULL;
}
return;
}
else
ObjError(olestat);
}
}
/* error if got to here */
wsprintf(szBuffer, "%s", (LPSTR)szOPropMenuStr);
InsertMenu(hMenu, EDITMENUPOS, MF_BYPOSITION,NULL,szBuffer);
EnableMenuItem(hMenu, EDITMENUPOS, MF_GRAYED|MF_BYPOSITION);
if (hkeyRoot)
{
RegCloseKey(hkeyRoot);
hkeyRoot = NULL;
}
}
void NEAR PASCAL MakeMenuString(char *szCtrl, char *szMenuStr, char *szVerb, char *szClass, char *szObject)
{
char *pStr;
register char c;
while (c = *szCtrl++)
{
switch(c)
{
case 'c': // class
case 'C': // class
pStr = szClass;
break;
case 'v': // class
case 'V': // class
pStr = szVerb;
break;
case 'o': // object
case 'O': // object
pStr = szObject;
break;
default:
*szMenuStr++ = c;
*szMenuStr = '\0'; // just in case
continue;
}
if (pStr) // should always be true
{
lstrcpy(szMenuStr,pStr);
szMenuStr += lstrlen(pStr); // point to '\0'
}
}
}
|