让MFC程序只能运行一个:
使用互斥对象CreateMutex();
BOOL CpipeApp::InitInstance()
{
m_hMute = ::CreateMutex(NULL, FALSE, "ss");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
return FALSE;
}
}
将已运行的实例调到前台
int CpipeDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
//添加窗口属性
::SetProp(m_hWnd, AfxGetApp()->m_pszExeName, (HANDLE)1);
return 0;
}
void CpipeDlg::OnDestroy()
{
CDialogEx::OnDestroy();
::RemoveProp(m_hWnd, AfxGetApp()->m_pszExeName);
}
BOOL CpipeAp