diff --git a/Cigarette/main.cpp b/Cigarette/main.cpp index 72dd525..b7b3c76 100644 --- a/Cigarette/main.cpp +++ b/Cigarette/main.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #if defined LICENSE_VERIFY #pragma comment(lib,"CryptoToolLib.lib") #include "CryptoToolLib.h" @@ -9,6 +11,18 @@ int main(int argc, char* argv[]) { + QApplication a(argc, argv); + HANDLE hMutex = NULL; + + hMutex = CreateMutex(nullptr, TRUE, L"CigratteShanghai"); + if ((GetLastError() == ERROR_ALREADY_EXISTS) || (hMutex == NULL)) { + QMessageBox::warning(nullptr, "Error", "An instance of the application is already running."); + CloseHandle(hMutex); + hMutex = NULL; + a.closeAllWindows(); + return 0; + } + #if defined LICENSE_VERIFY if (!VerifyLicense()) { @@ -16,7 +30,6 @@ int main(int argc, char* argv[]) } #endif qRegisterMetaType("cv::Mat"); - QApplication a(argc, argv); QPixmap pixmap("D:/Release/splash.jpg"); QSplashScreen splash(pixmap); splash.show(); @@ -25,5 +38,12 @@ int main(int argc, char* argv[]) w.show(); //w.showFullScreen(); splash.finish(&w); - return a.exec(); + a.exec(); + + if (hMutex != NULL) { + CloseHandle(hMutex); + hMutex = NULL; + } + + return 0; }