1.在CWinApp类中添加一个变量
HANDLE hMutex;
2.在InintInstance()中添加如下代码:
CString szClassName="SHUTDOWN";
hMutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,szClassName);
if(hMutex==NULL)
hMutex=CreateMutex(NULL,TRUE,szClassName);
else
{
MessageBox(0,"程序已经打开,不能重复运行!/t","警告",MB_OK|MB_ICONERROR);
return FALSE;
}
3.在ExitInstance()中添加如下代码:
if(hMutex!=NULL)
ReleaseMutex(hMutex);
HANDLE hMutex;
2.在InintInstance()中添加如下代码:
CString szClassName="SHUTDOWN";
hMutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,szClassName);
if(hMutex==NULL)
hMutex=CreateMutex(NULL,TRUE,szClassName);
else
{
MessageBox(0,"程序已经打开,不能重复运行!/t","警告",MB_OK|MB_ICONERROR);
return FALSE;
}
3.在ExitInstance()中添加如下代码:
if(hMutex!=NULL)
ReleaseMutex(hMutex);