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;

 

 

 

 

posted @ 2014-04-10 14:52  疯封风  阅读(558)  评论(0)    收藏  举报