• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

QtQProcess嵌入word、excel、ppt

武飞扬头像
daqinzl
帮助1

#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();

}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgbkhic
系列文章
更多 icon
同类精品
更多 icon
继续加载