12181
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
1 /* Add entries to the GNU Emacs Program Manager folder.
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
2 Copyright (C) 1995 Free Software Foundation, Inc.
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
3
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
4 This file is part of GNU Emacs.
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
5
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
6 GNU Emacs is free software; you can redistribute it and/or modify it
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
7 under the terms of the GNU General Public License as published by the
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
8 Free Software Foundation; either version 2, or (at your option) any later
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
9 version.
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
10
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
11 GNU Emacs is distributed in the hope that it will be useful, but WITHOUT
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
14 more details.
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
15
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
16 You should have received a copy of the GNU General Public License along
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
17 with GNU Emacs; see the file COPYING. If not, write to the Free Software
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
19 */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
20
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
21 /* addpm: Adds entries to the GNU Emacs Program Manager folder.
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
22
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
23 argv[1] = full path to program to execute
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
24 argv[2] = full path to icon for emacs (optional)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
25 */
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
26
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
27 #include <windows.h> // required for all Windows applications
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
28 #include <ddeml.h> // required for DDEML
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
29 #include <string.h> // required for strcpy and strlen
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
30
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
31 HDDEDATA EXPENTRY dde_callback (WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
32 BOOL send_shell_command (DWORD, LPSTR);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
33
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
34 // Global variables
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
35 HANDLE gh_inst; // current instance
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
36
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
37 /****************************************************************************
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
38 FUNCTION: WinMain()
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
39
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
40 PURPOSE: Calls initialization function, processes message loop
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
41
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
42 PARAMETERS:
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
43 HANDLE h_instance
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
44 HANDLE h_prev_instance
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
45 LPSTR lp_cmd_line
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
46 int n_cmd_show
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
47
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
48 RETURNS:
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
49 int
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
50 ****************************************************************************/
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
51
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
52 int PASCAL
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
53 WinMain (HANDLE h_instance, // current instance
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
54 HANDLE h_prev_instance, // previous instance
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
55 LPSTR lp_cmd_line, // command line
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
56 int n_cmd_show) // show-window type (open/icon)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
57 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
58 DWORD id_inst = 0L; // instance identifier
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
59 FARPROC lp_dde_proc;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
60 char *path, *icon, *s;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
61 char additem[MAX_PATH*2 + 100];
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
62
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
63 gh_inst = h_instance;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
64
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
65 for (path = NULL, s = lp_cmd_line; *s && isspace (*s); s++);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
66 if (*s)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
67 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
68 path = s;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
69 while (*s && !isspace (*s))
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
70 s++;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
71 if (*s)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
72 *(s++) = '\0';
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
73 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
74 for (icon = NULL; *s && isspace (*s); s++);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
75 if (*s)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
76 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
77 icon = s;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
78 while (*s && !isspace (*s))
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
79 s++;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
80 if (*s)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
81 *(s++) = '\0';
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
82 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
83
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
84 lp_dde_proc = MakeProcInstance ((FARPROC) dde_callback, gh_inst);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
85
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
86 DdeInitialize (&id_inst, // receives instance ID
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
87 (PFNCALLBACK) lp_dde_proc, // address of callback function
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
88 APPCMD_CLIENTONLY, // this is a client app
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
89 0L); // reserved
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
90
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
91 send_shell_command (id_inst, (LPSTR) "[CreateGroup(Gnu Emacs)]");
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
92
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
93 send_shell_command (id_inst, (LPSTR) "[ReplaceItem(Emacs)]");
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
94
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
95 sprintf (additem, "[AddItem(%s,Emacs%c%s)]",
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
96 path, (icon ? ',' : ' '), (icon ? icon : ""));
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
97 send_shell_command (id_inst, additem);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
98
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
99 DdeUninitialize (id_inst);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
100
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
101 return (0);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
102 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
103
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
104
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
105 /****************************************************************************
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
106 FUNCTION: dde_callback()
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
107
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
108 PURPOSE: Processes messages for DDEML conversation
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
109
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
110 PARAMETERS:
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
111 WORD w_type
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
112 WORD w_fmt
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
113 HCONV h_conv
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
114 HSZ hsz1
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
115 HSZ hsz2
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
116 HDDEDATA h_data
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
117 DWORD dw_data1
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
118 DWORD dw_data2
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
119
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
120 RETURNS:
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
121 HDDEDATA
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
122 ****************************************************************************/
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
123
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
124 HDDEDATA EXPENTRY
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
125 dde_callback (WORD w_type, // transaction type
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
126 WORD w_fmt, // clipboard format
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
127 HCONV h_conv, // handle of the conversation
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
128 HSZ hsz1, // handle of a string
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
129 HSZ hsz2, // handle of a string
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
130 HDDEDATA h_data, // handle of a global memory object
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
131 DWORD dw_data1, // transaction-specific data
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
132 DWORD dw_data2) // transaction-specific data
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
133 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
134 // Nothing need be done here...
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
135 return (HDDEDATA) NULL;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
136 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
137
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
138
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
139 /****************************************************************************
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
140 FUNCTION: send_shell_command()
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
141
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
142 PURPOSE: Sends the given command string to Program Manager
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
143
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
144 PARAMETERS:
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
145 LPSTR - pointer to command string
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
146
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
147 RETURNS:
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
148 BOOL - TRUE if this function succeeds, FALSE otherwise
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
149 ****************************************************************************/
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
150
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
151 BOOL
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
152 send_shell_command (DWORD id_inst, // instance identifier
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
153 LPSTR lp_command) // command string to execute
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
154 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
155 HSZ hsz_serv_top; // Service and Topic name are "PROGMAN"
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
156 HCONV hconv; // handle of conversation
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
157 int n_len; // length of command string
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
158 HDDEDATA h_data; // return value of DdeClientTransaction
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
159 DWORD dw_result; // result of transaction
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
160 BOOL b_result = FALSE; // TRUE if this function is successful
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
161
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
162 // create string handle to service/topic
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
163 hsz_serv_top = DdeCreateStringHandle (id_inst, "PROGMAN", CP_WINANSI);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
164
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
165 // attempt to start conversation with server app
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
166 if ((hconv = DdeConnect (id_inst, hsz_serv_top, hsz_serv_top, NULL))
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
167 != (HCONV) NULL)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
168 {
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
169 // get length of the command string
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
170 n_len = lstrlen ((LPSTR) lp_command);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
171
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
172 // send command to server app
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
173 h_data = DdeClientTransaction ((LPBYTE) lp_command, // data to pass
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
174 n_len + 1, // length of data
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
175 hconv, // handle of conversation
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
176 (HCONV) NULL, // handle of name-string
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
177 CF_TEXT, // clipboard format
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
178 XTYP_EXECUTE, // transaction type
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
179 1000, // timeout duration
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
180 &dw_result); // transaction result
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
181
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
182 if (h_data)
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
183 b_result = TRUE;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
184
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
185 // end conversation
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
186 DdeDisconnect (hconv);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
187 }
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
188
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
189 // free service/topic string handle
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
190 DdeFreeStringHandle (id_inst, hsz_serv_top);
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
191
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
192 return b_result;
|
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff
changeset
|
193 }
|