一、获取程序句柄以及类
打开Visual Studio 进行查询
二、QT调用程序
H文件
#ifndef VISUAL_H
#define VISUAL_H
#include <QWidget>
#include <QProcess>
#include<Windows.h>
#include<QWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class Visual; }
QT_END_NAMESPACE
class Visual : public QWidget
{
Q_OBJECT
public:
Visual(QWidget *parent = nullptr);
~Visual();
private:
Ui::Visual *ui;
QProcess *process;
QWindow * m_window;
};
#endif // VISUAL_H
CPP文件
#include "visual.h"
#include "ui_visual.h"
Visual::Visual(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Visual)
{
ui->setupUi(this);
process = new QProcess(this);
QString cmd = "C:/Users/CSJ/Desktop/CeleX5Demo_x64/CeleXDemo.exe";
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = true;
bool bRet = CreateProcess(
NULL,
(LPWSTR)cmd.toStdWString().c_str(),
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL, &si, &pi);
Sleep(1000);
WId wid = (WId)FindWindow(L"Qt5QWindowIcon", L"CeleXDemo");//获取窗口句柄
m_window = QWindow::fromWinId(wid);
m_window->setFlags(m_window->flags() | Qt::CustomizeWindowHint | Qt::WindowTitleHint); //
QWidget *m_widget;
m_widget = QWidget::createWindowContainer(m_window, this->ui->widget);
m_widget->setMinimumSize(1938, 1048);
}
Visual::~Visual()
{
delete ui;
}
最终效果:
完成QT外部调用!!