Eviter de lancer 2 fois le même programme
Bonjour,
je suis passé de C++Builder 2007 à C++Builder 2009.
Pour éviter dse lancer 2 fois la même application j'utilise :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
HANDLE hMutex;
try
{
char nom[256];
AnsiString asNom = Application->ExeName;
strcpy(nom, asNom.c_str());
hMutex=CreateMutex(NULL, TRUE, nom);
if( (hMutex==NULL) || (GetLastError() == ERROR_ALREADY_EXISTS) )
{
// Fermeture du Mutex
CloseHandle(hMutex);
Application->Title="";
HWND hPrevApp=::FindWindow(NULL, nom);
if(hPrevApp)
PostMessage(hPrevApp, WM_SYSCOMMAND, SC_RESTORE, 0);
return 0;
}
// Cacher l'application de la barre des tâches
SetWindowLong(Application->Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
Application->Initialize();
Application->Title = "Heure-Internet";
Application->CreateForm(__classid(TForm1), &Form1);
Application->CreateForm(__classid(TfSites), &fSites);
Application->CreateForm(__classid(TfReglages), &fReglages);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//--------------------------------------------------------------------------- |
Maintenant le programme ne se lance plus.
Quelqu'un aurait-il une idée de l'origine du problème ?
Merci.