QString exePath = QDir::currentPath() + "/test.exe";
QProcess *process = new QProcess(this);
process->start(exePath);
if (!process->waitForStarted()) {QMessageBox::critical(this, "Error", "无法启exe程序.");return;
}
//QThread::msleep(500);
HWND externalWindowHandle = findWindowByTitle(L"name");
if (externalWindowHandle == NULL) {QMessageBox::critical(this, "Error", "找不到exe程序窗口.");return;
}QWidget *container = QWidget::createWindowContainer(QWindow::fromWinId((WId)externalWindowHandle), this);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(container);
setLayout(layout);
注意事项:
1.test.exe同级文件全部拷贝到你程序的根目录。
2.在程序showEvent后调用findWindowByTitle;或者休眠。