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
|
/** BEGIN COPYRIGHT BLOCK
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
/****************************************************************************
PROGRAM: pmddeml.c
PURPOSE: DDEML interface with ProgMan
****************************************************************************/
#include <windows.h> // required for all Windows applications
#include <ddeml.h> // required for DDEML
#include <stdio.h> // required for strcpy and strlen
#include "nt/ntos.h" // specific to this program
BOOL PMDDEML_SendShellCommand (DWORD idInst, LPSTR lpCommand);
HDDEDATA CALLBACK PMDDEML_DdeCallback( UINT uType, // transaction type
UINT uFmt, // clipboard data format
HCONV hconv, // handle of the conversation
HSZ hsz1, // handle of a string
HSZ hsz2, // handle of a string
HDDEDATA hdata,// handle of a global memory object
DWORD dwData1, // transaction-specific data
DWORD dwData2 // transaction-specific data
);
/****************************************************************************
FUNCTION: PMDDEML_Open()
PURPOSE: Open PMDDEML interface
PARAMETERS:
RETURNS:
DWORD handle used in subsequent calls
****************************************************************************/
DWORD PMDDEML_Open ( void )
{
DWORD idInst = 0L; // instance identifier
// register this app with the DDEML
if (DdeInitialize(&idInst, // receives instance ID
(PFNCALLBACK)PMDDEML_DdeCallback, // address of callback function
APPCMD_CLIENTONLY, // this is a client app
0L)) // reserved
return 0;
return idInst;
}
/****************************************************************************
FUNCTION: PMDDEML_Close()
PURPOSE: Closes PMDDEML interface
PARAMETERS:
DWORD idInst handle returned by PMDDEML_Open
RETURNS:
TRUE, if successful
****************************************************************************/
BOOL PMDDEML_Close ( DWORD idInst )
{
// free all DDEML resources associated with this app
return DdeUninitialize ( idInst );
}
/****************************************************************************
FUNCTION: PMDDEML_CreateProgramManagerGroup()
PURPOSE: Creates a program group
PARAMETERS:
DWORD idInst handle returned by PMDDEML_Open
LPCTSTR lpszGroupNamee name of group
RETURNS:
TRUE, if successful
****************************************************************************/
BOOL PMDDEML_CreateProgramManagerGroup ( DWORD idInst, LPCTSTR lpszGroupName )
{
char szDDEMsg[256]; // instance identifier
if ( lpszGroupName == NULL )
return FALSE;
sprintf ( szDDEMsg, "[CreateGroup(%s)]", lpszGroupName );
if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
return FALSE;
return TRUE;
}
/****************************************************************************
FUNCTION: PMDDEML_DeleteProgramManagerGroup()
PURPOSE: Deletes a program group
PARAMETERS:
DWORD idInst handle returned by PMDDEML_Open
LPCTSTR lpszGroupNamee name of group
RETURNS:
TRUE, if successful
****************************************************************************/
BOOL PMDDEML_DeleteProgramManagerGroup ( DWORD idInst, LPCTSTR lpszGroupName )
{
char szDDEMsg[256]; // instance identifier
if ( lpszGroupName == NULL )
return FALSE;
sprintf ( szDDEMsg, "[DeleteGroup(%s)]", lpszGroupName );
if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
return FALSE;
return TRUE;
}
BOOL PMDDEML_DeleteProgramCommonManagerGroup ( DWORD idInst,
LPCTSTR lpszGroupName )
{
char szDDEMsg[256]; // instance identifier
if ( lpszGroupName == NULL )
return FALSE;
sprintf ( szDDEMsg, "[DeleteGroup(%s,1)]", lpszGroupName );
if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
return FALSE;
return TRUE;
}
/****************************************************************************
FUNCTION: PMDDEML_ShowProgramManagerGroup()
PURPOSE: Deletes a program group
PARAMETERS:
DWORD idInst handle returned by PMDDEML_Open
LPCTSTR lpszGroupNamee name of group
RETURNS:
TRUE, if successful
****************************************************************************/
BOOL PMDDEML_ShowProgramManagerGroup ( DWORD idInst, LPCTSTR lpszGroupName )
{
char szDDEMsg[256]; // instance identifier
if ( lpszGroupName == NULL )
return FALSE;
sprintf ( szDDEMsg, "[ShowGroup(%s,1)]", lpszGroupName );
if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
return FALSE;
return TRUE;
}
BOOL PMDDEML_ShowProgramManagerCommonGroup ( DWORD idInst,
LPCTSTR lpszGroupName )
{
char szDDEMsg[256]; // instance identifier
if ( lpszGroupName == NULL )
return FALSE;
sprintf ( szDDEMsg, "[ShowGroup(%s,1,1)]", lpszGroupName );
if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
return FALSE;
return TRUE;
}
/****************************************************************************
FUNCTION: PMDDEML_AddIconToProgramManagerGroup()
PURPOSE: Deletes icon a program group
PARAMETERS:
DWORD idInst handle returned by PMDDEML_Open
LPCTSTR lpszCmdLine title of icon in group
LPCTSTR lpszTitle title of icon in group
LPCTSTR lpszWorkingDir title of icon in group
BOOL bReplace True, if icon should be replaced
RETURNS:
TRUE, if successful
****************************************************************************/
BOOL PMDDEML_AddIconToProgramManagerGroup ( DWORD idInst, LPCTSTR lpszCmdLine,
LPCTSTR lpszTitle, LPCTSTR lpszIconPath, LPCTSTR lpszWorkingDir, BOOL bReplace )
{
char szDDEMsg[256]; // instance identifier
if ( ( lpszCmdLine == NULL ) || ( lpszTitle == NULL ) || ( lpszWorkingDir == NULL ) )
return FALSE;
if ( bReplace ) {
sprintf ( szDDEMsg, "[ReplaceItem(%s)]", lpszTitle );
PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg );
}
sprintf ( szDDEMsg, "[AddItem(%s,%s,%s,,,,%s)]", lpszCmdLine, lpszTitle,
lpszIconPath, lpszWorkingDir );
if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
return FALSE;
return TRUE;
}
/****************************************************************************
FUNCTION: PMDDEML_DeleteIconInProgramManagerGroup()
PURPOSE: Deletes icon a program group
PARAMETERS:
DWORD idInst handle returned by PMDDEML_Open
LPCTSTR lpszTitle title of icon in group
RETURNS:
TRUE, if successful
****************************************************************************/
BOOL PMDDEML_DeleteIconInProgramManagerGroup ( DWORD idInst, LPCTSTR lpszTitle )
{
char szDDEMsg[256]; // instance identifier
if ( lpszTitle == NULL )
return FALSE;
sprintf ( szDDEMsg, "[DeleteItem(%s)]", lpszTitle );
if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
return FALSE;
return TRUE;
}
/****************************************************************************
FUNCTION: PMDDEML_DdeCallback()
PURPOSE: Processes messages for DDEML conversation
PARAMETERS:
UINT uType, // transaction type
UINT uFmt, // clipboard data format
HCONV hconv, // handle of the conversation
HSZ hsz1, // handle of a string
HSZ hsz2, // handle of a string
HDDEDATA hdata,// handle of a global memory object
DWORD dwData1, // transaction-specific data
DWORD dwData2 // transaction-specific data
RETURNS:
HDDEDATA
****************************************************************************/
HDDEDATA CALLBACK PMDDEML_DdeCallback( UINT uType, // transaction type
UINT uFmt, // clipboard data format
HCONV hconv, // handle of the conversation
HSZ hsz1, // handle of a string
HSZ hsz2, // handle of a string
HDDEDATA hdata,// handle of a global memory object
DWORD dwData1, // transaction-specific data
DWORD dwData2 // transaction-specific data
)
{
// Nothing need be done here...
return (HDDEDATA)NULL;
}
/****************************************************************************
FUNCTION: PMDDEML_SendShellCommand()
PURPOSE: Sends the given command string to Program Manager
PARAMETERS:
LPSTR - pointer to command string
RETURNS:
BOOL - TRUE if this function succeeds, FALSE otherwise
****************************************************************************/
BOOL PMDDEML_SendShellCommand (DWORD idInst, // instance identifier
LPSTR lpCommand) // command string to execute
{
HSZ hszServTop; // Service and Topic name are "PROGMAN"
HCONV hconv; // handle of conversation
int nLen; // length of command string
HDDEDATA hData; // return value of DdeClientTransaction
DWORD dwResult; // result of transaction
BOOL bResult=FALSE; // TRUE if this function is successful
// create string handle to service/topic
hszServTop = DdeCreateStringHandle(idInst, "PROGMAN", CP_WINANSI);
// attempt to start conversation with server app
if ((hconv = DdeConnect(idInst, hszServTop, hszServTop, NULL))!= NULL)
{
// get length of the command string
nLen = lstrlen((LPSTR)lpCommand);
// send command to server app
hData = DdeClientTransaction((LPBYTE)lpCommand, // data to pass
nLen + 1, // length of data
hconv, // handle of conversation
NULL, // handle of name-string
CF_TEXT, // clipboard format
XTYP_EXECUTE, // transaction type
1000, // timeout duration
&dwResult); // points to transaction result
if (hData)
bResult = TRUE;
// end conversation
DdeDisconnect(hconv);
}
// free service/topic string handle
DdeFreeStringHandle(idInst, hszServTop);
return bResult;
}
/****************************************************************************
FUNCTION: PMDDEML_GetProgramGroupInfo()
PURPOSE: Gets group info from progman
PARAMETERS:
LPSTR - pointer to command string
RETURNS:
BOOL - TRUE if this function succeeds, FALSE otherwise
****************************************************************************/
BOOL PMDDEML_GetProgramGroupInfo(DWORD idInst, LPSTR lpProgramGroup, char *szBuffer, DWORD cbBuffer)
{
HSZ hszServTop; // Service and Topic name are "PROGMAN"
HSZ hszTopic; // Topic name is the lpRequest
HCONV hconv; // handle of conversation
HDDEDATA hData = 0; // return value of DdeClientTransaction
DWORD dwResult; // result of transaction
BOOL bResult=FALSE; // TRUE if this function is successful
hszServTop = DdeCreateStringHandle(idInst, "PROGMAN", CP_WINANSI);
hszTopic = DdeCreateStringHandle(idInst, lpProgramGroup, CP_WINANSI);
if((hconv = DdeConnect(idInst, hszServTop, hszServTop, NULL)) != NULL)
{
hData = DdeClientTransaction((LPBYTE)NULL, // data to pass
0L, // length of data
hconv, // handle of conversation
hszTopic, // handle of name-string
CF_TEXT, // clipboard format
XTYP_REQUEST, // transaction type
5000, // timeout duration
&dwResult); // points to transaction result
bResult = (BOOL)DdeGetData(hData, (void FAR*)szBuffer, cbBuffer, 0);
DdeDisconnect(hconv);
}
// free service/topic string handle
DdeFreeStringHandle(idInst, hszServTop);
DdeFreeStringHandle(idInst, hszTopic);
return bResult;
}
|