We have some code that works and it's a Win32 app with a GUI, but I would like to be able to trigger it from the command line as well (silent mode). Is there any easy way to do this? Or do I have to create another project as a command line application?
views:
45answers:
3If you want the application to be absolutely invisible, i.e. no window at all, you simply have to skip the part of your application that creates the main window. A normal command line application will create a console window, which will flash on the screen as the application opens and closes.
You can write a small application which start your old GUI application with respect of CreateProcess
Windows API. CreateProcess
has lpStartupInfo
parameter of the type STARTUPINFO
or STARTUPINFOEX
. If you initialize wShowWindow
field of this STARTUPINFO
or STARTUPINFOEX
to SW_HIDE
, then the main Windows of application which will be started will be hidden. You must also set dwFlags
of STARTUPINFO
or STARTUPINFOEX
which includes STARTF_USESHOWWINDOW
bit mask.
Such small program starting another program in hidden mode can be also used to start a console application without opening a well known console window.