diff options
author | Geoff Voelker <voelker@cs.washington.edu> | 1996-05-03 18:29:10 +0000 |
---|---|---|
committer | Geoff Voelker <voelker@cs.washington.edu> | 1996-05-03 18:29:10 +0000 |
commit | c911543b1c6cb0c2e40b8e2d0df98a8c7a4b0fb0 (patch) | |
tree | 3460ffdec7cf4997e0f212afb0e1ea020f7b0e99 /nt/runemacs.c | |
parent | 14f29224a0377ecf267326c3d64bf67c6795b378 (diff) | |
download | emacs-c911543b1c6cb0c2e40b8e2d0df98a8c7a4b0fb0.tar.gz |
Initial revision
Diffstat (limited to 'nt/runemacs.c')
-rw-r--r-- | nt/runemacs.c | 80 |
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; +} |