Companion command line window on Windows #1532
-
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
As I'm not a regular Windows user I had to do a quick search online, and this StackOverflow entry looks most appropriate: https://stackoverflow.com/questions/18260508/c-how-do-i-hide-a-console-window-on-startup It looks like either calling ShowWindow to hide the console: ::ShowWindow(::GetConsoleWindow(), SW_HIDE); Or linking the application with -mwindows. Hopefully actual Windows experts can chime in here... |
Beta Was this translation helpful? Give feedback.
-
There's a linker flag For a CMake project, this is controlled by the
It's better to do this than to pass the linker flags explicitly as the linker flag that controls this is different for different compilers (e.g. If you need
If you don't need to write any console output, then setting |
Beta Was this translation helpful? Give feedback.
-
Thanks so much for your help! I had previously tried to add the linker option for Windows builds in Cmake using It didn't solve the problem. So taking your advice I've let CMAKE do the hard work. I'm writing for Linux and Windows (with Mac to follow) and I want to be able to pass in command line options. The Solution that worked for me is:
Both Linux and Windows work and there is no more command line window in Windows (smiley face). Cheers, |
Beta Was this translation helpful? Give feedback.
-
Good to hear you've found a solution, even if it is a bit more hacky than it should all because, well Microsoft love corrupting standards... Another workaround that might be worth trying is redirecting std::cout and std::cerr to the vsg::Logger and registering a logger than passes stuff on to Windows reporting system. From vsgviewer.cpp: // if we want to redirect std::cout and std::cerr to the vsg::Logger call vsg::Logger::redirect_stdout()
if (arguments.read({"--redirect-std", "-r"})) vsg::Logger::instance()->redirect_std(); |
Beta Was this translation helpful? Give feedback.
There's a linker flag
/SUBSYSTEM
on Windows that determines whether your application uses the command-line subsystem (where the entrypoint for the application ismain
and standard streams are preconfigured) or the Windows subsystem (where the entrypoint isWinMain
and you need to explicitly configure the standard streams). It also controls whether a terminal window is spawned automatically if the parent process doesn't provide one.For a CMake project, this is controlled by the
WIN32_EXECUTABLE
target property, which can be set by:CMAKE_WIN32_EXECUTABLE
variable before the target's declared.WIN32
…