16,471
社区成员
发帖
与我相关
我的任务
分享
// Create the mutex with the class name
m_hMutex = CreateMutex(NULL, FALSE, m_strClassName);
// Check for errors
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
// Reset our mutex handle (just in case)
m_hMutex = NULL;
// The mutex already exists: an instance is already
// running. Find the app window and bring it to foreground
HWND hWnd = FindWindowEx(NULL, NULL, m_strClassName, NULL);
if ( hWnd != NULL ) {
ShowWindow( hWnd, SW_RESTORE );
BringWindowToTop( hWnd );
SetForegroundWindow( hWnd );
}
// Return failure
return FALSE;
}