增加程序不能重复打开的功能

main
Jinhuan 9 months ago
parent ca135833a0
commit cc8ce53abc

@ -2,6 +2,8 @@
#include <QtWidgets/QApplication>
#include <QPixmap>
#include <QSplashScreen>
#include <Windows.h>
#include <qmessagebox.h>
#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>("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;
}

Loading…
Cancel
Save