2

I have an app that opens the console and then it opens the GUI, but the console does not disappear.

Is there any way of hiding the console window?

Thanks

Almo
  • 15,538
  • 13
  • 67
  • 95
Tiago Couto
  • 351
  • 3
  • 9
  • Hiding the console is not something C will do for you. That will depend on the display system you're using. – Almo May 27 '15 at 21:25
  • 1
    what system/framework are you builing on? – bolov May 27 '15 at 21:26
  • I think that what you're looking for is a daemon process ( http://en.wikipedia.org/wiki/Daemon_%28computing%29). Maybe a duplicate of this post: http://stackoverflow.com/questions/5384168/how-to-make-a-process-daemon – Alessandro Suglia May 27 '15 at 21:30
  • 4
    Don't compile it as a console executable: [How to have an executable file run without a console?](http://stackoverflow.com/questions/29882262/how-to-have-an-executable-file-run-without-a-console) – Jongware May 27 '15 at 21:46

1 Answers1

5
#include <windows.h>

int main(void) {

    printf("%s", "Hello from the console.\n");

    MessageBox(NULL, "Click OK to hide the console.", "", MB_ICONINFORMATION);

    ShowWindow(GetConsoleWindow(), SW_HIDE);

    MessageBox(NULL, "Console is now hidden.", "", MB_ICONINFORMATION);

    return 0;
}
ThreeStarProgrammer57
  • 2,906
  • 2
  • 16
  • 24
  • If you really don't want the console window at all, instead call [`FreeConsole`](https://msdn.microsoft.com/en-us/library/ms683150). – Eryk Sun May 28 '15 at 08:09
  • Should that not be ``? – Xantium May 18 '18 at 19:28
  • @Simon possible, tbh I don't understand the rule. Could you explain why should this be ``? – ThreeStarProgrammer57 May 19 '18 at 20:51
  • You would use `include` when `windows.h` is in your library (the standard one). You would use `#include "windows.h"` when `windows.h` is along with your c file (or in a sub dictionary in which case it would be `#include"sub_file/windows.h"`. – Xantium May 19 '18 at 20:54
  • I thought the `windows.h` header is always part of the standard library. In which case it should be `` – Xantium May 19 '18 at 20:59