Search This Blog

Friday, December 19, 2008

MFC Code to avoid a Application running Many times

Paste this following code in BOOL CYourProjectNameApp::InitInstance() function of you Aplliction.


CreateMutex(NULL,TRUE,"Sample");
// mutex will be automatically deleted when process ends.
BOOL bAlreadyRunning = (GetLastError() == ERROR_ALREADY_EXISTS);
if(bAlreadyRunning)
{
::MessageBox(NULL, "This Appliction is Already Running ", "Information",
MB_ICONINFORMATION|MB_OK|MB_DEFBUTTON1);
return 0;
}

No comments: