4

I want to hide my console of C when I run my application. How can I make my application run in the background?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Siddiqui
  • 7,392
  • 15
  • 73
  • 128
  • My application contain many different processes which are for the full fulling the functionality of user. But the user only interact with main GUI, so that I want to hide all other processes. – Siddiqui Mar 11 '10 at 04:02

4 Answers4

5

Programs with main() by default are compiled as SUBSYSTEM:CONSOLE applications and get a console window. If you own the other processes your application is starting, you could modify them to be windowed applications by one of the following methods:

  • Modify them to use WinMain() instead of main(). This is the typical approach but requires modifying code. (If the reason for using main() is for easy access to argc/argv, MSVC provides global __argc/__argv equivalents for windowed applications.)
  • Explicitly specifying the subsystem and entry point via /SUBSYSTEM:WINDOWS /ENTRY:main arguments to link.exe.
  • Use editbin.exe to change the subsystem type after the fact. This one might be useful if you don't have source code access to the spawned processes.
jamesdlin
  • 65,531
  • 13
  • 129
  • 158
2

The easiest way to do this is to use a Windows Forms project rather than Console and then hide the startup form. The other option of course is a Windows Service, but this might be overkill ...

Bermo
  • 4,901
  • 1
  • 27
  • 31
0

If I remember correctly, there's no way to do it programmatically. There are options to do it. I think I have done it in the past by creating a Windows project, but having no Windows Forms code (I am just including the files from my console application). No console window popped up. I believe I did it in Code::Blocks once by changing an option in the GUI. I am sorry I can't be specific, but I am using Visual Studio 2010 RC and the way I do it there may not be the same as yours.

Your comment makes me think that you're spawning processes. You do it by the function you call. I don't know what language you're using (I'll assume C, because you said you're launching a C application you created?), but there is either a flag to say hide the window or (or a flag you don't set to not show it) or use an alternative function which does the same thing, but launches the process a different way. Try shellexecute and system().

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
0

Use CreateProcess with the DETACH_PROCESS flag.

Jerry Coffin
  • 455,417
  • 76
  • 598
  • 1,067