aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-06-20 02:53:59 +0000
committerRichard M. Stallman1995-06-20 02:53:59 +0000
commit6fbcbee7e5224974ddc1bce70b84c0233de7a5f8 (patch)
tree3f35a501f06c2bdf5260e90543715f75edabfa73
parent4e043ed3064fec8133ee4bf680c59b017c497515 (diff)
downloademacs-6fbcbee7e5224974ddc1bce70b84c0233de7a5f8.tar.gz
emacs-6fbcbee7e5224974ddc1bce70b84c0233de7a5f8.zip
Mostly rewritten.
-rw-r--r--nt/addpm.c199
1 files changed, 44 insertions, 155 deletions
diff --git a/nt/addpm.c b/nt/addpm.c
index 395748f8a05..2355b6701cc 100644
--- a/nt/addpm.c
+++ b/nt/addpm.c
@@ -18,176 +18,65 @@
18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21/* addpm: Adds entries to the GNU Emacs Program Manager folder.
22
23 argv[1] = full path to program to execute
24 argv[2] = full path to icon for emacs (optional)
25 */
26
27#include <windows.h> // required for all Windows applications
28#include <ddeml.h> // required for DDEML
29#include <string.h> // required for strcpy and strlen
30
31HDDEDATA EXPENTRY dde_callback (WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
32BOOL send_shell_command (DWORD, LPSTR);
33
34// Global variables
35HANDLE gh_inst; // current instance
36
37/**************************************************************************** 21/****************************************************************************
38 FUNCTION: WinMain() 22 *
23 * Program: addpm (adds emacs to the Windows program manager)
24 *
25 * Usage:
26 * argv[1] = full path to program to execute
27 * argv[2] = full path to icon for emacs (optional)
28 */
39 29
40 PURPOSE: Calls initialization function, processes message loop 30#include <windows.h>
31#include <ddeml.h>
32#include <stdlib.h>
33#include <stdio.h>
41 34
42 PARAMETERS: 35HDDEDATA CALLBACK DdeCallback (UINT uType, UINT uFmt, HCONV hconv,
43 HANDLE h_instance 36 HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
44 HANDLE h_prev_instance 37 DWORD dwData1, DWORD dwData2)
45 LPSTR lp_cmd_line 38{
46 int n_cmd_show 39 return ((HDDEDATA)NULL);
40}
47 41
48 RETURNS: 42#define DdeCommand(str) \
49 int 43 DdeClientTransaction (str, strlen(str)+1, HConversation, (HSZ)NULL, \
50****************************************************************************/ 44 CF_TEXT, XTYP_EXECUTE, 30000, NULL)
51 45
52int PASCAL 46main (argc, argv)
53WinMain (HANDLE h_instance, // current instance 47 int argc;
54 HANDLE h_prev_instance, // previous instance 48 char *argv[];
55 LPSTR lp_cmd_line, // command line
56 int n_cmd_show) // show-window type (open/icon)
57{ 49{
58 DWORD id_inst = 0L; // instance identifier 50 DWORD idDde;
59 FARPROC lp_dde_proc; 51 HCONV HConversation;
60 char *path, *icon, *s; 52 HSZ ProgMan;
61 char additem[MAX_PATH*2 + 100]; 53 char additem[MAX_PATH*2 + 100];
62 54
63 gh_inst = h_instance; 55 if (argc < 2 || argc > 3)
64
65 for (path = NULL, s = lp_cmd_line; *s && isspace (*s); s++);
66 if (*s)
67 {
68 path = s;
69 while (*s && !isspace (*s))
70 s++;
71 if (*s)
72 *(s++) = '\0';
73 }
74 for (icon = NULL; *s && isspace (*s); s++);
75 if (*s)
76 { 56 {
77 icon = s; 57 fprintf(stderr, "usage: addpm exe_path [icon_path]\n");
78 while (*s && !isspace (*s)) 58 exit(1);
79 s++;
80 if (*s)
81 *(s++) = '\0';
82 } 59 }
83
84 lp_dde_proc = MakeProcInstance ((FARPROC) dde_callback, gh_inst);
85
86 DdeInitialize (&id_inst, // receives instance ID
87 (PFNCALLBACK) lp_dde_proc, // address of callback function
88 APPCMD_CLIENTONLY, // this is a client app
89 0L); // reserved
90 60
91 send_shell_command (id_inst, (LPSTR) "[CreateGroup(Gnu Emacs)]"); 61 DdeInitialize (&idDde, (PFNCALLBACK)DdeCallback, APPCMD_CLIENTONLY, 0);
92 62
93 send_shell_command (id_inst, (LPSTR) "[ReplaceItem(Emacs)]"); 63 ProgMan = DdeCreateStringHandle (idDde, "PROGMAN", CP_WINANSI);
94 64
95 sprintf (additem, "[AddItem(%s,Emacs%c%s)]", 65 if (HConversation = DdeConnect (idDde, ProgMan, ProgMan, NULL))
96 path, (icon ? ',' : ' '), (icon ? icon : ""));
97 send_shell_command (id_inst, additem);
98
99 DdeUninitialize (id_inst);
100
101 return (0);
102}
103
104
105/****************************************************************************
106 FUNCTION: dde_callback()
107
108 PURPOSE: Processes messages for DDEML conversation
109
110 PARAMETERS:
111 WORD w_type
112 WORD w_fmt
113 HCONV h_conv
114 HSZ hsz1
115 HSZ hsz2
116 HDDEDATA h_data
117 DWORD dw_data1
118 DWORD dw_data2
119
120 RETURNS:
121 HDDEDATA
122****************************************************************************/
123
124HDDEDATA EXPENTRY
125dde_callback (WORD w_type, // transaction type
126 WORD w_fmt, // clipboard format
127 HCONV h_conv, // handle of the conversation
128 HSZ hsz1, // handle of a string
129 HSZ hsz2, // handle of a string
130 HDDEDATA h_data, // handle of a global memory object
131 DWORD dw_data1, // transaction-specific data
132 DWORD dw_data2) // transaction-specific data
133{
134 // Nothing need be done here...
135 return (HDDEDATA) NULL;
136}
137
138
139/****************************************************************************
140 FUNCTION: send_shell_command()
141
142 PURPOSE: Sends the given command string to Program Manager
143
144 PARAMETERS:
145 LPSTR - pointer to command string
146
147 RETURNS:
148 BOOL - TRUE if this function succeeds, FALSE otherwise
149****************************************************************************/
150
151BOOL
152send_shell_command (DWORD id_inst, // instance identifier
153 LPSTR lp_command) // command string to execute
154{
155 HSZ hsz_serv_top; // Service and Topic name are "PROGMAN"
156 HCONV hconv; // handle of conversation
157 int n_len; // length of command string
158 HDDEDATA h_data; // return value of DdeClientTransaction
159 DWORD dw_result; // result of transaction
160 BOOL b_result = FALSE; // TRUE if this function is successful
161
162 // create string handle to service/topic
163 hsz_serv_top = DdeCreateStringHandle (id_inst, "PROGMAN", CP_WINANSI);
164
165 // attempt to start conversation with server app
166 if ((hconv = DdeConnect (id_inst, hsz_serv_top, hsz_serv_top, NULL))
167 != (HCONV) NULL)
168 { 66 {
169 // get length of the command string 67 DdeCommand ("[CreateGroup(Gnu Emacs)]");
170 n_len = lstrlen ((LPSTR) lp_command); 68 DdeCommand ("[ReplaceItem(Emacs)]");
171 69 sprintf (additem, "[AddItem(%s,Emacs%c%s)]",
172 // send command to server app 70 argv[1], (argc>2 ? ',' : ' '),
173 h_data = DdeClientTransaction ((LPBYTE) lp_command, // data to pass 71 (argc>2 ? argv[2] : ""));
174 n_len + 1, // length of data 72 DdeCommand (additem);
175 hconv, // handle of conversation 73
176 (HCONV) NULL, // handle of name-string 74 DdeDisconnect (HConversation);
177 CF_TEXT, // clipboard format
178 XTYP_EXECUTE, // transaction type
179 1000, // timeout duration
180 &dw_result); // transaction result
181
182 if (h_data)
183 b_result = TRUE;
184
185 // end conversation
186 DdeDisconnect (hconv);
187 } 75 }
188 76
189 // free service/topic string handle 77 DdeFreeStringHandle (idDde, ProgMan);
190 DdeFreeStringHandle (id_inst, hsz_serv_top); 78
79 DdeUninitialize (idDde);
191 80
192 return b_result; 81 return (0);
193} 82}