From cc8ce53abcaab0c76e374e4ecbad103dd60d3b74 Mon Sep 17 00:00:00 2001 From: Jinhuan <412100639@qq.com> Date: Sun, 21 Apr 2024 19:29:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A8=8B=E5=BA=8F=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E9=87=8D=E5=A4=8D=E6=89=93=E5=BC=80=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cigarette/main.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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; }