#include "DataControlCenter.h"
#include <QtWidgets/QApplication>
#include <windows.h>
#include <tlhelp32.h>
#include <QMessageBox>
bool isRuning(QString strName) {
/*说明:判断进程是否已经存在运行实例依赖windowsAPI*/int i = 0;
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(pe32);
HANDLE hProcesssnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcesssnap == INVALID_HANDLE_VALUE)
{
i += 0;
}
bool bMore = ::Process32First(hProcesssnap, &pe32);
while (bMore)
{
QString strProcessName = QString::fromWCharArray(pe32.szExeFile);
if (strProcessName == strName)
{
i++;
}
bMore = ::Process32Next(hProcesssnap, &pe32);
}
return(i > 1) ? true : false;//大于1,排除自身
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
if (isRuning(a.applicationFilePath().split("/").last())) {
QMessageBox::about(NULL, "错误", "请勿重复运行本程序!");
return -1;
}
DataControlCenter w;
w.show();
return a.exec();
}
如果工程中没有包含#include <windows.h>也会报错,TlHelp32.h中使用的DWORD、HANDLE等类型都在windows.h中定义
720

被折叠的 条评论
为什么被折叠?



