Files
chenzhen 222dda1e43 1,新增“App_ThermalImageSystem”;
2,新增“Apps”;
3,新增“Common”;
4,新增“FileList”;
5,新增“MediaX”;
6,新增“OpenSource”;
7,新增“Samples”;
8,新增“SoftwareBusinessLines”.
2026-02-14 23:03:23 +08:00

314 lines
7.7 KiB
C++

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QMessageBox>
#include <QFileDialog>
#include <QString>
#include <QDebug>
#include "commonhelper.h"
#include "frameless_helper.h"
#include <mmsystem.h>
#pragma comment(lib, "winmm")
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//
m_bMousePressed = false;
//
m_bWindowMenu = false;
//
m_bThreadRunning_CaptureDeviceData = false;
m_ptrThread_CaptureDeviceData = nullptr;
// 初始化界面
InitStyle();
//
this->setFixedWidth(800);
ui->wgtTitleBar->setFixedWidth(790);
// 加载信号槽函数连接
Connect();
// 加载多进程
LoadMultiProcess();
}
MainWindow::~MainWindow()
{
//
StopThread_DealDeviceData();
Disconnect();
UnloadMultiProcess();
delete ui;
}
void MainWindow::Connect()
{
// 通用
connect(ui->m_pushButton_MinMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
connect(ui->m_pushButton_CloseMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
// 视频采集
connect(&m_varTimer, &QTimer::timeout, this, &MainWindow::OnTimer);
m_varTimer.setTimerType(Qt::PreciseTimer);
m_varTimer.start(40);
}
void MainWindow::Disconnect()
{
// 通用
disconnect(ui->m_pushButton_MinMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
disconnect(ui->m_pushButton_CloseMenu, &QPushButton::clicked, this, &MainWindow::OnButtonClicked);
m_varTimer.stop();
disconnect(&m_varTimer, &QTimer::timeout, this, &MainWindow::OnTimer);
}
bool MainWindow::LoadMultiProcess()
{
QString strAppPath = QCoreApplication::applicationDirPath();
// process01
QString strCmd01 = strAppPath + "/Process01.exe";
STARTUPINFO si_process01 = { sizeof(STARTUPINFO) };
PROCESS_INFORMATION pi_process01 = {0};
si_process01.dwFlags = STARTF_USESHOWWINDOW;
si_process01.wShowWindow = true;
bool bRet01 = CreateProcess(
NULL,
(LPWSTR)strCmd01.toStdWString().c_str(),
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL, &si_process01, &pi_process01);
WaitForInputIdle((HANDLE)pi_process01.dwProcessId, INFINITE);
QThread::msleep(2000);
//
WId nWinID_01 = (WId)FindWindow(L"Qt5QWindowIcon", L"MainWindow_Process01");
QWindow* pWindow_01 = QWindow::fromWinId(nWinID_01);
pWindow_01->setFlags(pWindow_01->flags() | Qt::CustomizeWindowHint | Qt::WindowTitleHint); //
QWidget* pWidget_01;
pWidget_01 = QWidget::createWindowContainer(pWindow_01, this, Qt::Widget);
ui->m_verticalLayout_Process01->addWidget(pWidget_01);
// process02
QString strCmd02 = strAppPath + "/Process02.exe";
STARTUPINFO si_process02 = { sizeof(STARTUPINFO) };
PROCESS_INFORMATION pi_process02 = {0};
si_process02.dwFlags = STARTF_USESHOWWINDOW;
si_process02.wShowWindow = true;
bool bRet02 = CreateProcess(
NULL,
(LPWSTR)strCmd02.toStdWString().c_str(),
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL, &si_process02, &pi_process02);
QThread::msleep(2000);
WaitForInputIdle((HANDLE)pi_process02.dwProcessId, INFINITE);
//
WId nWinID_02 = (WId)FindWindow(L"Qt5QWindowIcon", L"MainWindow_Process02");
QWindow* pWindow_02 = QWindow::fromWinId(nWinID_02);
pWindow_02->setFlags(pWindow_02->flags() | Qt::CustomizeWindowHint | Qt::WindowTitleHint); //
QWidget* pWidget_02;
pWidget_02 = QWidget::createWindowContainer(pWindow_02, this, Qt::Widget);
ui->m_verticalLayout_Process02->addWidget(pWidget_02);
return true;
}
void MainWindow::UnloadMultiProcess()
{
system("taskkill /f /t /im Process01.exe");
system("taskkill /f /t /im Process02.exe");
}
void MainWindow::OnButtonClicked()
{
// 最小化
if(sender() == ui->m_pushButton_MinMenu)
{
this->showMinimized();
}
// 退出程序
if(sender() == ui->m_pushButton_CloseMenu)
{
qApp->exit();
}
}
void MainWindow::OnComboxIndexChanged(int nIndex)
{
}
void MainWindow::InitStyle()
{
m_bMousePressed = false;
//安装事件监听器,让标题栏识别鼠标双击
ui->lblTitle->installEventFilter(this);
this->setWindowFlags(/*Qt::FramelessWindowHint
| Qt::WindowSystemMenuHint
|*/ Qt::WindowMinimizeButtonHint);
FramelessHelper *pHelper = new FramelessHelper(this);
pHelper->activateOn(this); //激活当前窗体
pHelper->setTitleHeight(ui->wgtTitleBar->height()); //设置窗体的标题栏高度
CommonHelper::SetStyle("blue");//"blue"//"dark"
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
//if (ui->lblTitle == obj)
{
if (event->type() == QEvent::MouseButtonPress)
{
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
if (mouseEvent->button() == Qt::LeftButton)
{
m_bMousePressed = true;
m_ptMouse = mouseEvent->globalPos() - pos();
mouseEvent->accept();
}
return true;
}
else if (event->type() == QEvent::MouseMove)
{
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
if (m_bMousePressed && this->windowState() != Qt::WindowMaximized)
{
if (mouseEvent->globalY() <= qApp->desktop()->availableGeometry().bottom())
{
move(mouseEvent->globalPos() - m_ptMouse);
mouseEvent->accept();
}
else
{
qApp->desktop()->cursor().setPos(
qApp->desktop()->cursor().pos().x(),
qApp->desktop()->availableGeometry().bottom()
);
}
}
return true;
}
else if (event->type() == QEvent::MouseButtonRelease)
{
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
if (mouseEvent->button() == Qt::LeftButton)
{
m_bMousePressed = false;
mouseEvent->accept();
}
return true;
}
}
return QMainWindow::eventFilter(obj, event);
}
void MainWindow::OnTimer()
{
}
void MainWindow::ThreadEntry(ThreadRunFunPtr pRunFun, void* pOwner)
{
MainWindow* pThis = reinterpret_cast<MainWindow*>(pOwner);
if (NULL == pThis)
{
return;
}
(pThis->*pRunFun)();
}
void MainWindow::ThreadFun_CaptureDeviceData()
{
timeBeginPeriod(1);
byte* pReadData = new byte[2688*1024+4096];
std::chrono::system_clock::time_point tm2_2 = std::chrono::system_clock::now();
int nTimeOutCount = 0;
while(m_bThreadRunning_CaptureDeviceData)
{
int nRes = 0;
}
timeEndPeriod(1);
}
bool MainWindow::StartThread_DealDeviceData()
{
StopThread_DealDeviceData();
//
m_bThreadRunning_CaptureDeviceData = true;
m_ptrThread_CaptureDeviceData = new std::thread(std::bind(&MainWindow::ThreadEntry, &MainWindow::ThreadFun_CaptureDeviceData, (void*)this));
return true;
}
void MainWindow::StopThread_DealDeviceData()
{
//
if(m_bThreadRunning_CaptureDeviceData)
{
m_bThreadRunning_CaptureDeviceData = false;
if(nullptr != m_ptrThread_CaptureDeviceData)
{
m_ptrThread_CaptureDeviceData->join();
delete m_ptrThread_CaptureDeviceData;
m_ptrThread_CaptureDeviceData = nullptr;
}
}
}