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;

04-14 12:25