Skip to content

Instantly share code, notes, and snippets.

@thinkhy
Created February 14, 2011 06:56
Show Gist options
  • Save thinkhy/825573 to your computer and use it in GitHub Desktop.
Save thinkhy/825573 to your computer and use it in GitHub Desktop.
mfc 应用程序的单例运行
BOOL InitInstance()
{
m_hMutex = ::CreateMutex(NULL, FALSE, APP_MUTEX_NAME);
if (NULL == m_hMutex)
{
Suicide();
return FALSE;
}
if (ERROR_ALREADY_EXISTS == GetLastError())
{
PTMessageBoxID1(IDS_APP_ALREADY_RUNNING, MB_OK|MB_ICONINFORMATION);
CloseHandle(m_hMutex);
Suicide();
return FALSE;
}
}
void Suicide()
{
TerminateProcess(GetCurrentProcess(),0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment