VC中判断程序是否已运行

 

 

// Try to create a mutex with the app's name


 HANDLE hMutexOneInstance = ::CreateMutex(NULL,TRUE,_T(AfxGetAppName()));

 

// Already there...means that we are already running an instance

if(::GetLastError() == ERROR_ALREADY_EXISTS)
{

       AfxMessageBox("程序已经运行!");

 

       if(hMutexOneInstance)
             ::ReleaseMutex(hMutexOneInstance);


       exit(0);       // 中止现运行程序

}

 

将上述代码放在OnInitialUpdate()或OnInitialDialog()中

你可能感兴趣的:(null)