CString strMutexName = "MySingleInstance";
HANDLE hMutex = CreateMutex(NULL,FALSE,strMutexName);
if ( hMutex )
{
if ( ERROR_ALREADY_EXISTS == ::GetLastError() )
{//如果已有先前的实例,则退出
HWND hWnd= ::FindWindow([程序窗口类名], [程序窗口名称]);
if( hWnd)
{
::ShowWindow( hWnd, SW_SHOWNORMAL);
::SetForegroundWindow( hWnd);
::BringWindowToTop( hWnd);
::FlashWindow( hWnd, TRUE );
}
exit(0);
}
}