让程序只运行一个实例的简单实用的方法

阅读 132

2023-01-24

//
//只能运行一个实例
HANDLE hMutexOneInstantance=CreateMutex(NULL,TRUE,_T("PreventSecondInstance"));
BOOL bFound=FALSE;
if(GetLastError()==ERROR_ALREADY_EXISTS)
bFound=TRUE;
if(hMutexOneInstantance)
ReleaseMutex(hMutexOneInstantance);
if (bFound==TRUE)
{
//::AfxMessageBox("您已经运行了一个实例");
return false;
}

精彩评论(0)

0 0 举报