46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
//---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#include <winuser.h>
|
|
#include <winbase.h>
|
|
|
|
#pragma hdrstop
|
|
USERES("CtrlDogs.res");
|
|
USEFORM("CtrlDog.cpp", Dog);
|
|
USEFORM("CtrlD_PasswordDlg.cpp", PasswordDlg);
|
|
//---------------------------------------------------------------------------
|
|
HINSTANCE g_hinst;
|
|
//extern "C" __declspec(dllimport) int _stdcall RegisterServiceProcess( DWORD dwProcessID, int dwType);
|
|
//function RegisterServiceProcess(dwProcessID, dwType: integer): integer; stdcall; external 'KERNEL32.DLL';
|
|
|
|
//---------------------------------------------------------------------------
|
|
WINAPI WinMain(HINSTANCE, HINSTANCE hInstance, LPSTR, int)
|
|
{
|
|
AnsiString FsMutex = DateToStr(TDateTime::CurrentDate()) + AnsiString("-mutex-dog");
|
|
|
|
// RegisterServiceProcess(GetCurrentProcessID(), 1); // Hide Aplication
|
|
// SetWindowLong(Application->Handle, GWL_EXSTYLE, XWndLong | WS_EX_TOOLWINDOW & ! WS_EX_APPWINDOW | WS_EX_TOPMOST);
|
|
|
|
HANDLE FhMutex = OpenMutex(MUTEX_ALL_ACCESS,False, FsMutex.c_str() );
|
|
if ( FhMutex == 0 ) //it's a first instance
|
|
{
|
|
FhMutex = CreateMutex(NULL,false, FsMutex.c_str() );
|
|
try
|
|
{
|
|
Application->Initialize();
|
|
g_hinst = hInstance;
|
|
Application->Title = "Sistema de Control";
|
|
Application->CreateForm(__classid(TDog), &Dog);
|
|
Application->ShowMainForm = false;
|
|
Application->Run();
|
|
}
|
|
catch (Exception &exception)
|
|
{
|
|
Application->ShowException(&exception);
|
|
}
|
|
} else {
|
|
if ( CloseHandle(FhMutex) ) FhMutex = 0;
|
|
}
|
|
return 0;
|
|
}
|
|
//---------------------------------------------------------------------------
|