Mercurial > emacs
comparison nt/addpm.c @ 12181:702f2ac242de
Initial revision
author | Geoff Voelker <voelker@cs.washington.edu> |
---|---|
date | Sat, 10 Jun 1995 02:24:19 +0000 |
parents | |
children | e97b20222345 |
comparison
equal
deleted
inserted
replaced
12180:268be0c80ca2 | 12181:702f2ac242de |
---|---|
1 /* Add entries to the GNU Emacs Program Manager folder. | |
2 Copyright (C) 1995 Free Software Foundation, Inc. | |
3 | |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify it | |
7 under the terms of the GNU General Public License as published by the | |
8 Free Software Foundation; either version 2, or (at your option) any later | |
9 version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, but WITHOUT | |
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
14 more details. | |
15 | |
16 You should have received a copy of the GNU General Public License along | |
17 with GNU Emacs; see the file COPYING. If not, write to the Free Software | |
18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 */ | |
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 | |
31 HDDEDATA EXPENTRY dde_callback (WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD); | |
32 BOOL send_shell_command (DWORD, LPSTR); | |
33 | |
34 // Global variables | |
35 HANDLE gh_inst; // current instance | |
36 | |
37 /**************************************************************************** | |
38 FUNCTION: WinMain() | |
39 | |
40 PURPOSE: Calls initialization function, processes message loop | |
41 | |
42 PARAMETERS: | |
43 HANDLE h_instance | |
44 HANDLE h_prev_instance | |
45 LPSTR lp_cmd_line | |
46 int n_cmd_show | |
47 | |
48 RETURNS: | |
49 int | |
50 ****************************************************************************/ | |
51 | |
52 int PASCAL | |
53 WinMain (HANDLE h_instance, // current instance | |
54 HANDLE h_prev_instance, // previous instance | |
55 LPSTR lp_cmd_line, // command line | |
56 int n_cmd_show) // show-window type (open/icon) | |
57 { | |
58 DWORD id_inst = 0L; // instance identifier | |
59 FARPROC lp_dde_proc; | |
60 char *path, *icon, *s; | |
61 char additem[MAX_PATH*2 + 100]; | |
62 | |
63 gh_inst = h_instance; | |
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 { | |
77 icon = s; | |
78 while (*s && !isspace (*s)) | |
79 s++; | |
80 if (*s) | |
81 *(s++) = '\0'; | |
82 } | |
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 | |
91 send_shell_command (id_inst, (LPSTR) "[CreateGroup(Gnu Emacs)]"); | |
92 | |
93 send_shell_command (id_inst, (LPSTR) "[ReplaceItem(Emacs)]"); | |
94 | |
95 sprintf (additem, "[AddItem(%s,Emacs%c%s)]", | |
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 | |
124 HDDEDATA EXPENTRY | |
125 dde_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 | |
151 BOOL | |
152 send_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 { | |
169 // get length of the command string | |
170 n_len = lstrlen ((LPSTR) lp_command); | |
171 | |
172 // send command to server app | |
173 h_data = DdeClientTransaction ((LPBYTE) lp_command, // data to pass | |
174 n_len + 1, // length of data | |
175 hconv, // handle of conversation | |
176 (HCONV) NULL, // handle of name-string | |
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 } | |
188 | |
189 // free service/topic string handle | |
190 DdeFreeStringHandle (id_inst, hsz_serv_top); | |
191 | |
192 return b_result; | |
193 } |