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)?)
Printable View
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)?)
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
[email protected]
Feel free to send questions.....
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.
Ok then, how can you then open up any files passed as parameters in the first instance.
Hi,
it's shown in the MSDN. Search for the article ID Q141752.
Martin
Please, can you describe your problem in more details. What do you want as the result?
Oleg.