Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A program running in the background...

Status
Not open for further replies.

PLV

Programmer
Apr 29, 2001
15
0
0
US
I'm a newbie programmer and I have to write a program that must to be running background (invisible an without any icons or dialogs). It will perform some actions on a database and write a log afterward.

There's sureley a way to do that easely...

Can U help?

Is my question clear enough cause I have some trouble writing english ;o) !!!



 
You can do this by using the CreateProcess(...) api.
If you are comfortable with APIs then this is the best API to use as the others are just wraps for this one. CreateProcess gives you great control of the app that has to executed.

BOOL CreateProcess(

LPCTSTR lpApplicationName, // pointer to name of executable module
LPTSTR lpCommandLine, // pointer to command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // pointer to process security attributes
LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to thread security attributes
BOOL bInheritHandles, // handle inheritance flag
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // pointer to new environment block
LPCTSTR lpCurrentDirectory, // pointer to current directory name
LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO
LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION
);

In the lpStartupInfo structure, set the wShowWindow parameter to SW_HIDE. This makes the app running invicisble.

You can also use the ShellExecute API:
HINSTANCE ShellExecute(

HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
);

The nShowCmd should be set to SW_HIDE.
Welcome to the Pythian Games!
Long live Godess Athena!
dArktEmplAr of Delphi Oracle
 
How about to do program without any windows?

for example is very correct to do like

#include<windows.h>
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
return 0;
}
simply make programs without making a window. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top