summaryrefslogtreecommitdiff
path: root/nt/runemacs.c
diff options
context:
space:
mode:
authorGeoff Voelker <voelker@cs.washington.edu>1996-05-03 18:29:10 +0000
committerGeoff Voelker <voelker@cs.washington.edu>1996-05-03 18:29:10 +0000
commit2569c82cdb60e344145a636062259dadd6bbba10 (patch)
tree56a5e7e5480e25cae2995af93ead7a7bed7e76e4 /nt/runemacs.c
parent476828a4d41c190bb0d836824d7b05c4cda1a696 (diff)
downloademacs-2569c82cdb60e344145a636062259dadd6bbba10.tar.gz
Initial revision
Diffstat (limited to 'nt/runemacs.c')
-rw-r--r--nt/runemacs.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/nt/runemacs.c b/nt/runemacs.c
new file mode 100644
index 00000000000..720c6ca7241
--- /dev/null
+++ b/nt/runemacs.c
@@ -0,0 +1,80 @@
+/*
+ Simple program to start Emacs with its console window hidden.
+
+ This program is provided purely for convenience, since most users will
+ use Emacs in windowing (GUI) mode, and will not want to have an extra
+ console window lying around. */
+
+#define WIN32
+
+#include <windows.h>
+#include <string.h>
+#include <malloc.h>
+
+int WINAPI
+WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow)
+{
+ STARTUPINFO start;
+ SECURITY_ATTRIBUTES sec_attrs;
+ SECURITY_DESCRIPTOR sec_desc;
+ PROCESS_INFORMATION child;
+ int wait_for_child = FALSE;
+ DWORD ret_code = 0;
+ char * new_cmdline;
+ char * p;
+ char modname[MAX_PATH];
+
+ if (!GetModuleFileName (NULL, modname, MAX_PATH))
+ goto error;
+ if ((p = strrchr (modname, '\\')) == NULL)
+ goto error;
+ *p = 0;
+
+ new_cmdline = alloca (MAX_PATH + strlen (cmdline) + 1);
+ strcpy (new_cmdline, modname);
+ strcat (new_cmdline, "\\emacs.exe ");
+
+ /* append original arguments if any; first look for -wait as first
+ argument, and apply that ourselves */
+ if (strncmp (cmdline, "-wait", 5) == 0)
+ {
+ wait_for_child = TRUE;
+ cmdline += 5;
+ }
+ strcat (new_cmdline, cmdline);
+
+ /* set emacs_dir variable if runemacs was in "%emacs_dir%\bin" */
+ if ((p = strrchr (modname, '\\')) && stricmp (p, "\\bin") == 0)
+ {
+ *p = 0;
+ SetEnvironmentVariable ("emacs_dir", modname);
+ }
+
+ memset (&start, 0, sizeof (start));
+ start.cb = sizeof (start);
+ start.dwFlags = STARTF_USESHOWWINDOW;
+ start.wShowWindow = SW_HIDE;
+
+ sec_attrs.nLength = sizeof (sec_attrs);
+ sec_attrs.lpSecurityDescriptor = NULL;
+ sec_attrs.bInheritHandle = FALSE;
+
+ if (CreateProcess (NULL, new_cmdline, &sec_attrs, NULL, TRUE, 0,
+ NULL, NULL, &start, &child))
+ {
+ if (wait_for_child)
+ {
+ WaitForSingleObject (child.hProcess, INFINITE);
+ GetExitCodeProcess (child.hProcess, &ret_code);
+ }
+ CloseHandle (child.hThread);
+ CloseHandle (child.hProcess);
+ }
+ else
+ goto error;
+ return (int) ret_code;
+
+error:
+ MessageBox (NULL, "Could not start Emacs.", "Error", MB_ICONSTOP);
+ return 1;
+}