|
@@ -0,0 +1,188 @@
|
|
|
+#include "home.h"
|
|
|
+#include "ui_home.h"
|
|
|
+#include <QDateTime>
|
|
|
+#include <QMessageBox>
|
|
|
+#include <QScreen>
|
|
|
+#include <QTimer>
|
|
|
+#include <QDebug>
|
|
|
+#include <QNetworkRequest>
|
|
|
+#include <QHttpMultiPart>
|
|
|
+#include <QNetworkAccessManager>
|
|
|
+#include <QFile>
|
|
|
+#include <QProcess>
|
|
|
+#include <QVBoxLayout>
|
|
|
+//#include <QtWin>
|
|
|
+//#include <QtWinExtras/qwinfunctions.h>
|
|
|
+#pragma comment(lib, "user32.lib")
|
|
|
+#include "httpapi.h"
|
|
|
+#include "qresource.h"
|
|
|
+
|
|
|
+#include <windows.h>
|
|
|
+#include <tlhelp32.h>
|
|
|
+#include <stdio.h>
|
|
|
+
|
|
|
+Home::Home(QWidget *parent) :
|
|
|
+ QMainWindow(parent),
|
|
|
+ ui(new Ui::Home)
|
|
|
+{
|
|
|
+ ui->setupUi(this);
|
|
|
+ myTimer = new QTimer(this);
|
|
|
+ //start timer for screen capture
|
|
|
+ connect(myTimer,&QTimer::timeout,[this](){
|
|
|
+ captureScreen();
|
|
|
+ });
|
|
|
+// myTimer->start(60000);
|
|
|
+
|
|
|
+ //set ui data
|
|
|
+ webWidget = new QWebEngineView(this);
|
|
|
+ QNetworkProxyFactory::setUseSystemConfiguration(false);
|
|
|
+
|
|
|
+ QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
|
+
|
|
|
+ mainLayout->addWidget(webWidget);
|
|
|
+// setLayout(mainLayout);
|
|
|
+ QWidget* widget = new QWidget(this);
|
|
|
+ widget->setLayout(mainLayout);
|
|
|
+ this->setCentralWidget(widget);
|
|
|
+
|
|
|
+ setWindowState(Qt::WindowMaximized);//最大化
|
|
|
+ QString str = "http://118.190.47.230:9095/#/login";
|
|
|
+ loadNavigate(str);
|
|
|
+
|
|
|
+
|
|
|
+ HANDLE hCurrentCursor = GetForegroundWindow();
|
|
|
+ qDebug()<<hCurrentCursor<<endl;
|
|
|
+// EnumWindows(StaticEnumWindowsProc,reinterpret_cast<LPARAM>(this));
|
|
|
+ PROCESSENTRY32 pe32;
|
|
|
+ //再使用这个结构体前先定义它的大小
|
|
|
+ pe32.dwSize=sizeof(pe32);
|
|
|
+ //给系统内的所有进程拍一个快照
|
|
|
+ HANDLE hProcessSnap=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
|
|
+ if (hProcessSnap==INVALID_HANDLE_VALUE)
|
|
|
+ {
|
|
|
+ printf("Create ToolHelp32Snaphhot调用失败!\n");
|
|
|
+
|
|
|
+ }
|
|
|
+ BOOL bMore=::Process32First(hProcessSnap,&pe32);
|
|
|
+ while(bMore)
|
|
|
+ {
|
|
|
+ qDebug()<<"进程名称="<<pe32.szExeFile<<"进程id="<<pe32.th32ProcessID;
|
|
|
+
|
|
|
+ bMore=::Process32Next(hProcessSnap,&pe32);
|
|
|
+ }
|
|
|
+ qDebug()<<"不要忘记清楚掉snapshot";
|
|
|
+ ::CloseHandle(hProcessSnap);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+BOOL Home::StaticEnumWindowsProc(HWND hwnd, LPARAM lParam)
|
|
|
+{
|
|
|
+ //窗口是否可视
|
|
|
+ if (!::IsWindowVisible(hwnd))
|
|
|
+ return TRUE;
|
|
|
+
|
|
|
+ //窗口是否可激活
|
|
|
+ if (!::IsWindowEnabled(hwnd))
|
|
|
+ return TRUE;
|
|
|
+
|
|
|
+ //确定给定窗口是否是最小化(图标化)的窗口。
|
|
|
+ //if(IsIconic(hwnd))
|
|
|
+ // return TRUE;
|
|
|
+
|
|
|
+ //窗口是否具有父窗口?
|
|
|
+ HWND hParent = (HWND)GetWindowLong(hwnd, -8);
|
|
|
+ //父窗口是否可激活?
|
|
|
+ //据 Spy++ 观察,如“运行”对话框等被应列入列表的程序有一个隐藏的,具有 WS_DISABLED 的父窗口
|
|
|
+ if (IsWindowEnabled(hParent))
|
|
|
+ return TRUE;
|
|
|
+ //父窗口是否可视?
|
|
|
+ if (IsWindowVisible(hParent))
|
|
|
+ return TRUE;
|
|
|
+
|
|
|
+ LONG gwl_style = GetWindowLong(hwnd, GWL_STYLE);
|
|
|
+ if ((gwl_style & WS_POPUP) && !(gwl_style & WS_CAPTION))
|
|
|
+ return TRUE;
|
|
|
+
|
|
|
+ CHAR caption[256];
|
|
|
+ memset(caption, 0, sizeof(caption));
|
|
|
+ ::GetWindowTextA(hwnd, caption, 255);
|
|
|
+
|
|
|
+ if (strcmp(caption, ""))
|
|
|
+ {
|
|
|
+ if (GetClassLong(hwnd, -14))
|
|
|
+ {
|
|
|
+ HICON hIcon =(HICON)GetClassLong(hwnd, -14);
|
|
|
+ if(hIcon)
|
|
|
+ {
|
|
|
+// handleIcon.push_back(hIcon);
|
|
|
+// handleWindow.push_back(hwnd);
|
|
|
+ qDebug()<<"hIcon="<<hIcon<<", title="<<GetClassLong(hwnd, -8);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ qDebug() <<"title=="<< caption;
|
|
|
+ }
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void Home::captureScreen() {
|
|
|
+ QScreen *screen = QGuiApplication::primaryScreen();
|
|
|
+ QString filePathName = "timeManager_screencap.jpg";
|
|
|
+ screen->grabWindow(0).save(filePathName, "jpg"); // 0值为整个电脑屏幕WId
|
|
|
+
|
|
|
+ //start upload file
|
|
|
+ QNetworkRequest request;
|
|
|
+ request.setUrl(QUrl(SERVER_URL + "/imageProcessing/saveAndProcessImage"));
|
|
|
+ QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
|
|
+ QHttpPart imagePart;
|
|
|
+ imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));//如果是png图片填image/png
|
|
|
+ imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"file\"; filename=\"image.jpg\""));
|
|
|
+ // imagePart.setRawHeader("Content-ID", "my@content.id"); // 添加任何你喜欢的 headers
|
|
|
+ QFile *file = new QFile(filePathName);
|
|
|
+ file->open(QIODevice::ReadOnly);
|
|
|
+ imagePart.setBodyDevice(file);
|
|
|
+ multiPart->append(imagePart);
|
|
|
+
|
|
|
+ //text paramter
|
|
|
+ QHttpPart textPart;
|
|
|
+ textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"uid\""));
|
|
|
+ textPart.setBody("2");
|
|
|
+ multiPart->append(textPart);
|
|
|
+ QHttpPart textPart2;
|
|
|
+ textPart2.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"indate\""));
|
|
|
+ QString indate = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
|
|
|
+ textPart2.setBody(indate.toUtf8());
|
|
|
+ multiPart->append(textPart2);
|
|
|
+
|
|
|
+ QString processList = getProcessList();
|
|
|
+ qDebug() << processList ;
|
|
|
+ QHttpPart textPart3;
|
|
|
+ textPart3.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"processList\""));
|
|
|
+ textPart3.setBody(processList.toUtf8());
|
|
|
+ multiPart->append(textPart3);
|
|
|
+
|
|
|
+ QNetworkAccessManager *m_pNetWorkManager = new QNetworkAccessManager();
|
|
|
+ m_pNetWorkManager->post(request, multiPart);
|
|
|
+}
|
|
|
+
|
|
|
+QString Home::getProcessList() {
|
|
|
+ QProcess process;
|
|
|
+ process.start("tasklist.exe");
|
|
|
+ if(process.waitForFinished())
|
|
|
+ {
|
|
|
+ QByteArray result = process.readAll();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+void Home::loadNavigate(QString sUrl)
|
|
|
+{
|
|
|
+ webWidget->load(sUrl);
|
|
|
+}
|
|
|
+Home::~Home()
|
|
|
+{
|
|
|
+ delete ui;
|
|
|
+}
|