Skip to content

Instantly share code, notes, and snippets.

@jebai0521
Forked from thinkhy/mfc_app_singleton_C++
Created January 5, 2017 07:13
Show Gist options
  • Save jebai0521/7f00846c0635961438d963cd453cf95f to your computer and use it in GitHub Desktop.
Save jebai0521/7f00846c0635961438d963cd453cf95f 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