I need it to take up as little processor time as possible and there's absolutely no need to create an actual window. I just need that process to hang out in the backdground.
-
What is your target platform? – Captain Giraffe Dec 03 '14 at 22:38
-
1Sounds like a Windows user. – Joseph Mansfield Dec 03 '14 at 22:39
-
2try a service perhaps? Besides using a Console – DJ Burb Dec 03 '14 at 22:41
-
Implement your application as a ervice (e.g. using *Qt*), try `FreeConsole()` or http://stackoverflow.com/questions/2139637/hide-console-of-windows-application – trylimits Dec 03 '14 at 22:45
2 Answers
Windows application are running always at background, and not have to be with GUI window, so this is what you ask for. If you already have a console application, you'll just need to do the following:
- In visual studio create an empty project (not a console, a Win32 app).
- Add new c++ source file into that project
- put the following code in the new source file:
this:
#include <Windows.h>
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
//your program should replace this loop:
while(1){
Sleep(100); //because of the the empty loop, I don't want to waste CPU...
}
return 0;
}
- use this
wWinMain
as yourmain
, if you need arguments you'll need to parse pCmdLine. - Note that this is the UNICODE version, for non UNICODE use just
WinMain
andPSTR pCmdLine
like this:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow)
- if your program needed to be stopped you can use task manager to kill it.
- a system try icon also can help you, but then you'll need at least one window (possibly hidden)

- 7,940
- 9
- 38
- 57
This request fits Windows Service concept best. The example. You may implement that many different ways, C/C++ with Qt or not/C#. The advantage of creating the service and not hidden console is that the program is manageable via standard Windows Service interface for (un)register/start/stop/etc. with both administrative UI and console utilities.
Making the app consuming less CPU is much more delicate thing and depends on what your app does but the simpler answer is that don't run tight loops and make it wait until it is needed to process something. There are too many things to cover e.g. threading etc. but we don't know what your program does.

- 8,351
- 4
- 38
- 47