#include "mainwindow.h"
#include <QApplication>
#include <QProcess>
#include <QObject>
#include <QWindow>
#include <windows.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
// Start child process
QProcess webProcess;
webProcess.start("\"C:\\Program Files\\Microsoft Office\\Office15\\WINWORD.EXE\"", QStringList() << ("D:\\test.docx"));
// Get child process handle
WId childId = (WId)FindWindow(L"OpusApp", NULL); //excel XLMAIN ppt PPTFrameClass
int n = 0;
while (true) {
Sleep(1);
childId = (WId)FindWindow(L"OpusApp", NULL);
if (childId != 0) {
break;
} else if(n++ > 15000) {
return 1;
}
}
HWND childHwnd = (HWND)childId;
// Put the child window in front first, and then put it back
SetWindowPos(childHwnd,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
SetWindowPos(childHwnd,HWND_BOTTOM,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
// Get the parent window's geometry
QRect rt = w.geometry();
// Get the child window object by id
QWindow *childWd;
childWd = QWindow::fromWinId(childId);
// Set child window geometry
childWd->setGeometry(rt);
// Get parent process handle
WId parentId = w.winId();
HWND parentHwnd = (HWND)parentId;
// Embedding child window into parent window
SetParent(childHwnd, parentHwnd);
w.show();
return a.exec();
}