App 的InitInstance函数中加入:
CString strName = "MakeHtml.exe "; // must be unique
CreateMutex(NULL,TRUE,strName);
if(GetLastError()== ERROR_ALREADY_EXISTS) // if name already exists
{
CWnd *pWndPrev, *pWndChild;
if (pWndPrev = CWnd::FindWindow(NULL, "Your Application Window Label "))
{
pWndChild = pWndPrev-> GetLastActivePopup();
if (pWndPrev-> IsIconic())
pWndPrev-> ShowWindow(SW_SHOW);
pWndChild-> SetForegroundWindow(); // bring it to foreground
}
//AfxMessageBox("当前应用程序已在运行.");
return FALSE;
}
编译运行,OK