PDA

View Full Version : Open a PowerPoint inside QMainWindow



blackout69
3rd July 2015, 23:52
Hi,
with this code I can open PowerPoint files (.ppt or .pptx)



FullScreen::FullScreen(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::FullScreen)
{
ui->setupUi(this);

QString file_ppt = "C:\\aaa.pptx";

// Open parameter
QList<QVariant> param_list;
param_list.append(file_ppt);
param_list.append(1);
param_list.append(0);
param_list.append(0);

// Make a object PPT
QAxWidget *obj_ppt = new QAxWidget("Powerpoint.Application", this->ui->slides);
obj_ppt->setGeometry(QRect(0,0,800,600));

if(!obj_ppt->setControl("{91493441-5A91-11CF-8700-00AA0060263B}"))
{
QMessageBox::critical(this, trUtf8("Error PPT"), "Install Microsoft Power Point (R) for the support PPT!");
}

// Open a template file
QAxObject *presentations = obj_ppt->querySubObject("Presentations");
QAxObject *presentation = presentations->querySubObject("Open(const QString&,int,int,int)", param_list);

// Start the slides
QAxObject *slideshow = presentation->querySubObject("SlideShowSettings");
slideshow->setProperty("RangeType", "ppShowAll");
slideshow->dynamicCall("run()");
}


What I want to obtain, is to show the slide into object QAxWidget called ui->slides centered in my form.
Instead I get to open the my form with a black rectangle of 800x600 pixels and a full screen slide out of the my form.
Someone can help me understand where I'm wrong?
Thanks.
blackout69

blackout69
5th July 2015, 18:38
hi,
I completely changing approach to the my problem, using setControl(), with the following code, I can open a Word document (.doc or .docx) inside my object QAxWidget ui->slides that have already positioned and centered on my form.


FullScreen::FullScreen(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::FullScreen)
{
ui->setupUi(this);

if(!ui->slides->setControl("Word.Application"))
{
QMessageBox::critical(this, trUtf8("Errore DOC"), "Installare Microsoft Word(R) per il supporto DOC!");
}
ui->slides->setControl("C:\\aaa.docx");
}

But following the same code for PowerPoint files (.ppt or .pptx), my item QAxWidget ui->slides become all white and the content of aaa.pptx will not appear. By controlling the task of Windows, I see that the program powerpnt.exe is running, only that the file aaa.pptx not shown.
There is anyone who has worked with objects QAxWidget to help me to understand where I'm wrong?:crying:


FullScreen::FullScreen(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::FullScreen)
{
ui->setupUi(this);

if(!ui->slides->setControl("PowerPoint.Application"))
{
QMessageBox::critical(this, trUtf8("Errore PPT"), "Installare Microsoft Power Point (R) per il supporto PPT!");
}
ui->slides->setControl("C:\\aaa.pptx");
}

thank you in advance
blackout69

zhaolan94
3rd October 2015, 15:32
This might helpful to you
http://stackoverflow.com/questions/11360758/embedding-a-powerpoint-show-into-a-c-sharp-application

blackout69
4th November 2015, 23:27
Thank zhaolan94 for your replay, but he did not understand how.
You could make a simple example?
Thank you