Click to See Complete Forum and Search --> : not loaded two time!!!
Mihai C.
September 8th, 1999, 02:55 AM
I want a application which will not be loaded if it is already loaded.
(how I can determnine if I an in the second "instance" of this application ?
(hPrevInstance from Win31)?)
Rotem
September 8th, 1999, 03:41 AM
Here is one option, though i bet there are better ones. You could keep a flag in the registry stating if there is a program of your running currently, then every program can check the flag and if it TRUE than it should close itself.
-----------------------------------------
Rotem Bentzur
Rotem.Bentzur@ecitele.com
Feel free to send questions.....
Oleg Lobach
September 8th, 1999, 03:56 AM
The are some ways, just now I remember two of them:
1. Use FindWindow
HWND hExist=FindWindow (0,szYourWindowTitle);
if (hExist)
return FALSE;
2.Create Mutex like this:
CreateMutex(NULL,TRUE,szAnyText); // mutex will be automatically deleted when process ends.
BOOL bAlreadyRunning = (GetLastError() == ERROR_ALREADY_EXISTS);
if(bAlreadyRunning){
char szMsg [256];
strcpy (szMsg, "Application already started");
m_pMainWnd->MessageBox (szMsg, "BLA_BLA_BLA",
MB_OK | MB_ICONWARNING | MB_APPLMODAL);
return FALSE;
}
The code above shouldbe placed in InitInstance.
Good luck,
Oleg.
MikeL
September 8th, 1999, 04:26 AM
Ok then, how can you then open up any files passed as parameters in the first instance.
Martin Speiser
September 8th, 1999, 04:38 AM
Hi,
it's shown in the MSDN. Search for the article ID Q141752.
Martin
Oleg Lobach
September 8th, 1999, 04:51 AM
Please, can you describe your problem in more details. What do you want as the result?
Oleg.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.