Qt 防止程序多次运行
关于程序多开的尝试。CreateMutex,OpenMuxtex,ReleaseMutex
Windows核心编程:使用 CreateMutex 防止运行应用程序的多个实例
//检查应用程序是否已运行
QString strAppName("AppName");
std::wstring wStr = strAppName.toStdWString();
LPCWSTR lpName = (LPCWSTR)wStr.c_str();
HANDLE hMutex = CreateMutex(NULL, FALSE, lpName);
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
CloseHandle(hMutex);
return 0;
}
...
if (hMutex != NULL)
CloseHandle(hMutex);
return 1;