1

I have a program which needs to call another program.

So after some research I found ShellExecuteEx command with appropriate SHELLEXECUTEINFO to call an external program. That works fine so far, but it pops up actually two windows: command line and the Qt-application with its window.

If I execute the Qt-application stand alone there is no command line window.

What I now want to achieve is getting rid of the console window and show only the window of the Qt-application. I tried to set the nShow property of SHELLEXECUTEINFO to SW_HIDE but than both windows are hidden.

I don't know if it matters but the caller program is compiled with vs2010 and the called program is compiled with visual studio 2017, both as 32-bit applications.

Feuerteufel
  • 571
  • 5
  • 16
  • Maybe `SEE_MASK_NO_CONSOLE` could be something to try. – super Feb 28 '19 at 14:10
  • unfortunately it does not work – Feuerteufel Feb 28 '19 at 14:33
  • 1
    By default `ShellExecuteExW` doesn't inherit the parent's console because the underlying `CreateProcessW` call uses the flag `CREATE_NEW_CONSOLE`. Using `SEE_MASK_NO_CONSOLE` makes it not use the latter flag, so it can inherit the parent's console. There's no difference if that parent doesn't have a console to inherit. – Eryk Sun Feb 28 '19 at 23:55
  • I'd first explore what's different about executing the app stand alone that avoids allocating a console. If it comes down to it, you can allocate a hidden console via `AllocConsole()` and `ShowWindow(GetConsoleWindow(), SW_HIDE)`. This will briefly flash a console. You can avoid the flash by using the following procedure instead: run cmd.exe via `CreateProcessW` with the flag `CREATE_NO_WINDOW` and the output info as `pi`; try `AttachConsole(pi.dwProcessId)` until it succeeds; then `TerminateProcess(pi.hProcess, 0)`; and finally `CloseHandle(pi.hThread)`, `CloseHandle(pi.hProcess)`. – Eryk Sun Mar 01 '19 at 00:02
  • I setup my projects with cmake and if I put `WIN32` to the executable, like `add_executable(project WIN32 ${sources})` it seems to suppress the console, but I actually don't know why exactly, maybe some internal cmake magic. – Feuerteufel Mar 01 '19 at 09:16
  • I just noticed, that WIN32 needs a WinMain as entry point, which seems to exist via Qt. – Feuerteufel Mar 01 '19 at 09:32

0 Answers0