Console or GUI at the same time

Hello,

I have an app that I want to launch as a GUI if you execute it with no parameters or as a console app if you pass some parameters.

It works ok-ish as when I launch the GUI it also has a console window in the background. How can I avoid this window?

So if I call c:> myapp.exe → shows GUI (and only GUI, no console)
if I call c:> myapp.exe par1 par2 par3 → shows console

Thanks in advance!

in your Main.cpp initialise function, just case in there on your command line params. If you want to show a GUI, set your mainWindow variable (mainWindow.reset(…)), else do what you need to do headless.

Thanks @darrenwin , I already do that. Something like

if (commandLine.isNotEmpty()) //exec command line app
{
doMyCalculations();
}
else //show gui
{
mMainWindow.reset(new MainWindow(getApplicationName()));
}

The problem is that when it goes through the GUI option it also shows the console on the background. And I don’t want to see this.

In my preprocessor definitions I have:
_CONSOLE;_CRT_SECURE_NO_WARNINGS;WIN32;_WINDOWS;

and if I remove _CONSOLE; (which I’m not sure I want to do that as when no parameters I want (just) the console, then I get a link error

Any other ideas?

I would start a new project with the GUI Application template. That won’t have that _CONSOLE and other console related settings in the build.

If it is run from the Explorer/double click, there are no arguments and you open the GUI.
If it is run from the terminal and arguments are supplied, you simply don’t create a window like suggested before. All works as intended.
The settings you have now are trying to open a terminal if not started from a terminal IIRC. But when you get cmd arguments, there is already a terminal, so no need for the _CONSOLE switch.

Ignoring arguments from a shortcut for now…

HTH

1 Like

Thanks @daniel , that did the trick.

If anyone needs this is under Linker->System: SubSystem: Windows (SUBSYSTEM:WINDOWS)

My project was as “CONSOLE”

Thanks!