Created
February 14, 2011 06:56
-
-
Save thinkhy/825573 to your computer and use it in GitHub Desktop.
mfc 应用程序的单例运行
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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