m_hMutex = ::CreateMutex(NULL, TRUE,
"互斥名(随便取)"
);
if
(GetLastError() == ERROR_ALREADY_EXISTS)
//程序已经运行
{
HWND
oldHWnd = NULL;
oldHWnd = ::FindWindow(NULL, _T(
"程序名"
));
//查找已经运行的程序
if
(oldHWnd)
{
::ShowWindow(oldHWnd, SW_SHOWNORMAL);
//激活显示找到的已运行的程序
::SetForegroundWindow(oldHWnd);
//将已运行的程序设置为当前窗口
}
CloseHandle(m_hMutex);
m_hMutex = NULL;
return
FALSE;
}