2 Simple program to start Emacs with its console window hidden.
4 This program is provided purely for convenience, since most users will
5 use Emacs in windowing (GUI) mode, and will not want to have an extra
6 console window lying around. */
15 WinMain (HINSTANCE hSelf
, HINSTANCE hPrev
, LPSTR cmdline
, int nShow
)
18 SECURITY_ATTRIBUTES sec_attrs
;
19 SECURITY_DESCRIPTOR sec_desc
;
20 PROCESS_INFORMATION child
;
21 int wait_for_child
= FALSE
;
25 char modname
[MAX_PATH
];
27 if (!GetModuleFileName (NULL
, modname
, MAX_PATH
))
29 if ((p
= strrchr (modname
, '\\')) == NULL
)
33 new_cmdline
= alloca (MAX_PATH
+ strlen (cmdline
) + 1);
34 strcpy (new_cmdline
, modname
);
35 strcat (new_cmdline
, "\\emacs.exe ");
37 /* append original arguments if any; first look for -wait as first
38 argument, and apply that ourselves */
39 if (strncmp (cmdline
, "-wait", 5) == 0)
41 wait_for_child
= TRUE
;
44 strcat (new_cmdline
, cmdline
);
46 /* set emacs_dir variable if runemacs was in "%emacs_dir%\bin" */
47 if ((p
= strrchr (modname
, '\\')) && stricmp (p
, "\\bin") == 0)
50 SetEnvironmentVariable ("emacs_dir", modname
);
53 memset (&start
, 0, sizeof (start
));
54 start
.cb
= sizeof (start
);
55 start
.dwFlags
= STARTF_USESHOWWINDOW
;
56 start
.wShowWindow
= SW_HIDE
;
58 sec_attrs
.nLength
= sizeof (sec_attrs
);
59 sec_attrs
.lpSecurityDescriptor
= NULL
;
60 sec_attrs
.bInheritHandle
= FALSE
;
62 if (CreateProcess (NULL
, new_cmdline
, &sec_attrs
, NULL
, TRUE
, 0,
63 NULL
, NULL
, &start
, &child
))
67 WaitForSingleObject (child
.hProcess
, INFINITE
);
68 GetExitCodeProcess (child
.hProcess
, &ret_code
);
70 CloseHandle (child
.hThread
);
71 CloseHandle (child
.hProcess
);
75 return (int) ret_code
;
78 MessageBox (NULL
, "Could not start Emacs.", "Error", MB_ICONSTOP
);