MFC只允许进行一个实例

APP---InitInstance()

放在所有程序运行前

//只允许运行一个实例 
 BOOL bfound = FALSE;
 hmutex = CreateMutex(NULL,TRUE,"preventSecondInstance");
 if (GetLastError() == ERROR_ALREADY_EXISTS)
 {
  bfound = TRUE;
 }
 if(bfound)
 {
  AfxMessageBox("程序己在运行");
  return FALSE;
 }

APP---ExitInstance

  if (hmutex)
   {
    ReleaseMutex(hmutex);
   }

//这个是全局变量

HANDLE hmutex;

原文地址:https://www.cnblogs.com/dengpeng1004/p/3656516.html