I wish to write a program that works in the background, i.e. without showing any windows. Someone prescribed i try this:
<code>
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
while(1)
{
Sleep(1000);
}

return 0;
}
<code>
but its not working. it still shows the CMD window. I am using Dev-C++. Could anyone advice me?

One, you have to specify to the linker that it's a windowed application.

Then you get the window handle, and with ShowWindow(), in the second parameter use SW_HIDE.

edit:
You'll probably also want to look into lowering the task priority.

Well, thanx. I have tried it but the compiler gives me so many errors and i still quite dont get it. By the way i am using vc++. Mind giving me a sample code? Will really appreciate. Thanx.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.