代码源自Jeffry Richter的著作《Windows核心编程》
在InitInstance()函数中写入以下代码:
//只运行一个实例
HANDLE hApp = CreateMutex(NULL,FALSE,"OnlyOneInstanceExample");
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
AfxMessageBox("Already Exist An Instance!");
return FALSE;
}
...
...//其它初始化代码
...
CloseHandle(hApp);
...
本文地址:http://com.8s8s.com/it/it797.htm