Brian T Hannan
Brian T Hannan

Reputation: 4005

Is it possible to allow a legacy Win32 GUI app to be run from command line as well?

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?

Upvotes: 0

Views: 208

Answers (3)

Oleg
Oleg

Reputation: 221997

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.

Upvotes: 1

Mark Ransom
Mark Ransom

Reputation: 308120

If 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.

Upvotes: 3

Edward Strange
Edward Strange

Reputation: 40859

c:> notepad.exe

That answer your question?

Upvotes: 1

Related Questions