#include "TestWidget.h"
#include <Windows.h>
#include "OfficeContainer.h"
DemoTestWidget::DemoTestWidget(QWidget *parent /*= NULL*/)
:m_index(1)
{
initUI();
initConnect();
this->showMaximized();
}
DemoTestWidget::~DemoTestWidget()
{
}
void DemoTestWidget::initUI()
{
pLblPath = new QLabel(tr("Path:"),this);
pTxtPath = new QLineEdit(this);
pBtnOpen = new QPushButton(tr("Open"),this);
pBtnSelect = new QPushButton(tr("Select"),this);
pBtnClose = new QPushButton(tr("Close"),this);
pComBox = new QComboBox(this);
/*
officeDialogNew = 0,
officeDialogOpen = 1,
officeDialogSave = 2,
officeDialogSaveCopy = 3,
officeDialogPrint = 4,
officeDialogPageSetup = 5,
officeDialogProperties = 6
*/
pComBox->addItem("officeDialogNew");
pComBox->addItem("officeDialogOpen");
pComBox->addItem("officeDialogSave");
pComBox->addItem("officeDialogSaveCopy");
pComBox->addItem("officeDialogPrint");
pComBox->addItem("officeDialogPageSetup");
pComBox->addItem("officeDialogProperties");
pBtnShowDlg = new QPushButton(tr("ShowDlg"),this);
/*QHBoxLayout *hly001 = new QHBoxLayout();
hly001->addWidget(pLblPath);
hly001->addWidget(pTxtPath);
hly001->addWidget(pBtnSelect);
hly001->addWidget(pBtnOpen);
hly001->addWidget(pBtnClose);
hly001->addWidget(pComBox);
hly001->addWidget(pBtnShowDlg);
pCentrelWgt = new QWidget(this);
pOfficeContainer = new OfficeContainer(this);
QVBoxLayout *vly0010 = new QVBoxLayout(pCentrelWgt);
vly0010->addWidget(pOfficeContainer,1);
QVBoxLayout *vly010 = new QVBoxLayout(this);
vly010->addLayout(hly001);
vly010->addWidget(pCentrelWgt,1);*/
//test
//officeContent=new QAxWidget("Powerpoint.Application",this);
//officeContent->setGeometry(QRect(10, 10, 1000, 1000));
//presentations = officeContent->querySubObject("Presentations");
//QHBoxLayout *hly001 = new QHBoxLayout();
//hly001->addWidget(pLblPath);
//hly001->addWidget(pTxtPath);
//hly001->addWidget(pBtnSelect);
//hly001->addWidget(pBtnOpen);
//hly001->addWidget(pBtnClose);
//hly001->addWidget(pComBox);
//hly001->addWidget(pBtnShowDlg);
//pCentrelWgt = new QWidget(this);
pOfficeContainer = new OfficeContainer(this);
//QVBoxLayout *vly0010 = new QVBoxLayout(pCentrelWgt);
//vly0010->addWidget(officeContent,1);
//QVBoxLayout *vly010 = new QVBoxLayout(this);
//vly010->addLayout(hly001);
//vly010->addWidget(pCentrelWgt,1);
//presentations->dynamicCall("Open(QString)", "C:\\Users\\LJ\\Desktop\\test.pptx");
//word
/*
officeContent=new QAxWidget("Word.Document",this);
officeContent->setGeometry(QRect(10, 10, 1000, 1000));officeContent->setControl("C:\\Users\\LJ\\Desktop\\test.docx");
officeContent->show();*/
//test2
officeContent=new QAxWidget("Powerpoint.Application",this);
officeContent->setGeometry(QRect(10, 10, 1000, 1000));
presentations = static_cast<PowerPoint::Presentations*>(officeContent->querySubObject("Presentations"));
//PowerPoint::Presentation *presentation;
//pptApp = new PowerPoint::Application();
//pptApp->dynamicCall("SetVisible(Office::MsoTriState)",true);
//PowerPoint::Presentations* presentations = pptApp->Presentations();
//PowerPoint::Presentation *presentation;
if (presentations != NULL )
{
//PowerPoint::Presentation *presentation = presentations->Open("C:\\Users\\LJ\\Desktop\\test.pptx");
//presentation = static_cast<PowerPoint::Presentation*>(presentations->querySubObject("Open(QString&)", "C:\\Users\\LJ\\Desktop\\test.pptx"));
presentation = static_cast<PowerPoint::Presentation*>(presentations->querySubObject("Open(QString&)", "D:\\test.pptx"));
//PowerPoint::Slides* slides = presentation->Slides();
slides = static_cast<PowerPoint::Slides*>(presentation->querySubObject("Slides()"));
QVariant index(m_index);
//PowerPoint::Slide* slide = slides->Item(index);
slide = static_cast<PowerPoint::Slide*>(slides->querySubObject("Item(QVariant&)", index));
m_index++;
//PowerPoint::SlideShowSettings* slideshow = presentation->SlideShowSettings();
slideshow = static_cast<PowerPoint::SlideShowSettings*>(presentation->querySubObject("SlideShowSettings()"));
//slideshow->Run();
slideshow->dynamicCall("Run()");
}
QHBoxLayout *hly001 = new QHBoxLayout();
hly001->addWidget(pLblPath);
hly001->addWidget(pTxtPath);
hly001->addWidget(pBtnSelect);
hly001->addWidget(pBtnOpen);
hly001->addWidget(pBtnClose);
hly001->addWidget(pComBox);
hly001->addWidget(pBtnShowDlg);
pCentrelWgt = new QWidget(this);
QVBoxLayout *vly0010 = new QVBoxLayout(pCentrelWgt);
vly0010->addWidget(officeContent,1);
QVBoxLayout *vly010 = new QVBoxLayout(this);
vly010->addLayout(hly001);
vly010->addWidget(pCentrelWgt,1);
//test3:
//officeContent=new QAxWidget("Powerpoint.Application",this);
//officeContent->setGeometry(QRect(10, 10, 1000, 1000));
//PowerPoint::Presentations* presentations = static_cast<PowerPoint::Presentations*>(officeContent->querySubObject("Presentations"));
//PowerPoint::Presentation *presentation;
pptApp = new PowerPoint::Application();
pptApp->dynamicCall("SetVisible(Office::MsoTriState)",true);
PowerPoint::Presentations* presentations = pptApp->Presentations();
PowerPoint::Presentation *presentation;
//if (presentations != NULL )
//{
// /*PowerPoint::Presentation **/presentation = presentations->Open("C:\\Users\\LJ\\Desktop\\test.pptx");
//}
//
//WId wid = (WId)FindWindow(L"PPTFrameClass",NULL);
第三步:获取QWindow
//QWindow *m_window;
//m_window = QWindow::fromWinId(wid);
//m_window->setFlags(m_window->flags() | Qt::CustomizeWindowHint | Qt::WindowTitleHint); //这边可以设置一下属性
第四步:获取代理QWidget
//QWidget *m_widget;
//m_widget = QWidget::createWindowContainer(m_window,this); //第二个参数是作为window的父类,也可以用layout,此处就不解释了
//
//QHBoxLayout *hly001 = new QHBoxLayout();
//hly001->addWidget(pLblPath);
//hly001->addWidget(pTxtPath);
//hly001->addWidget(pBtnSelect);
//hly001->addWidget(pBtnOpen);
//hly001->addWidget(pBtnClose);
//hly001->addWidget(pComBox);
//hly001->addWidget(pBtnShowDlg);
//pCentrelWgt = new QWidget(this);
//QVBoxLayout *vly0010 = new QVBoxLayout(pCentrelWgt);
//vly0010->addWidget(m_widget,1);
//QVBoxLayout *vly010 = new QVBoxLayout(this);
//vly010->addLayout(hly001);
//vly010->addWidget(pCentrelWgt,1);
/*m_widget = new QWidget(this);
m_widget->setStyleSheet(QString("background-color: rgb(0, 0, 0);"));
m_widget->setGeometry(0,0,1000,1000);
m_widget->show();
m_widget->setWindowOpacity(0.1);
m_widget->installEventFilter(this);*/
setAutoFillBackground(false);
setAttribute(Qt::WA_TranslucentBackground, true);
setWindowFlags(Qt::FramelessWindowHint);
installEventFilter(this);
HWND wid = (HWND)(this->winId());
//SetWindowLong(wid, GWL_EXSTYLE, GetWindowLong(wid, GWL_EXSTYLE) | WS_EX_NOACTIVATE | WS_EX_COMPOSITED);
SetWindowLong(wid, GWL_EXSTYLE, GetWindowLong(wid, GWL_EXSTYLE) | WS_EX_NOACTIVATE);
//HWND wid2 = (HWND)(m_widget->winId());
//SetWindowLong(wid2, GWL_EXSTYLE, GetWindowLong(wid2, GWL_EXSTYLE) | WS_EX_NOACTIVATE | WS_EX_COMPOSITED);
//slideShowWindow = static_cast<PowerPoint::SlideShowWindow*>(presentation->querySubObject("SlideShowWindow()"));
//installEventFilter(this);
}
void DemoTestWidget::initConnect()
{
BUTTON_ACT(pBtnOpen,sltBtnOpen());
BUTTON_ACT(pBtnSelect,sltBtnSelect());
BUTTON_ACT(pBtnClose,sltBtnClose());
BUTTON_ACT(pBtnShowDlg,sltBtnShowDlg());
}
void DemoTestWidget::sltBtnOpen()
{
/*QString strPath = pTxtPath->text();
if (!strPath.isEmpty())
{
QVariant v(strPath);
pOfficeContainer->Open(v);
}*/
qDebug() << "Btn Open";
//test
//presentations->dynamicCall("Open(QString)", "C:\Users\LJ\Desktop\test.pptx");
//test2
//PowerPoint::Slides* slides = static_cast<PowerPoint::Slides*>(presentation->querySubObject("Slides()"));
slideShowWindow = static_cast<PowerPoint::SlideShowWindow*>(presentation->querySubObject("SlideShowWindow()"));
slideShowView = static_cast<PowerPoint::SlideShowView*>(slideShowWindow->querySubObject("View()"));
//slideShowView.Next();
slideShowView->dynamicCall("Next()");
//slideShowView->dynamicCall("GotoSlide(int)", 4);
m_index++;
//slideShowView->dynamicCall("GotoClick(int)", PowerPoint::msoClickStateAfterAllAnimations);
int sum = slideShowView->GetClickCount(); //当前页的动画个数
/*QMessageBox msgBox;
msgBox.setText(QString::number(sum));
msgBox.exec();*/
}
void DemoTestWidget::sltBtnSelect()
{
QString filePath = QFileDialog::getOpenFileName(this,tr("Select Word"),"",tr("Word (*.doc;*.docx;*.docm);;Excel (*.xls;*.xlsx;*.xlsm;*.xlsb);;PPT (*.ppt;*.pptx;*.pptm)"));
if (filePath.isEmpty())
{
//emit sigUpdateMsg("未选择Word文件");
}
else
{
pTxtPath->setText(filePath);
}
qDebug() << "Btn Select";
}
void DemoTestWidget::sltBtnClose()
{
pOfficeContainer->Close();
}
void DemoTestWidget::sltBtnShowDlg()
{
int index = pComBox->currentIndex();
pOfficeContainer->ShowDialog((OfficeContainer::DialogType)(index));
}
bool DemoTestWidget::eventFilter(QObject *target, QEvent *event)
{
//if(target == m_widget)
{
qDebug("The imageWidget generate the event!");
if(event->type() == QEvent::MouseButtonPress)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if(mouseEvent->buttons() & Qt::LeftButton)
{
qDebug("The Left Button Event!");
slideShowWindow = static_cast<PowerPoint::SlideShowWindow*>(presentation->querySubObject("SlideShowWindow()"));
slideShowView = static_cast<PowerPoint::SlideShowView*>(slideShowWindow->querySubObject("View()"));
SetCursorPos(500,0);//这个坐标是“开始”这个菜单在我当前电脑屏幕上的位置,大家可以自己去获取
mouse_event( MOUSEEVENTF_LEFTDOWN, 0,0,0,NULL);//鼠标down事件
mouse_event( MOUSEEVENTF_LEFTUP, 0,0,0,NULL);//鼠标up事件
//QAxWidget* slideShowWindowWidget = static_cast<QAxWidget*>(presentation->querySubObject("SlideShowWindow()"));
//slideShowWindow->mousePressEvent( (QMouseEvent *)event);
//slideShowView.Next();
//slideShowView->dynamicCall("Next()");
}
return true;
}
/*switch (event->type())
{
case QEvent::KeyPress:
{
QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(event);
if (pKeyEvent->key() == Qt::Key_Escape)
{
return true;
}
}
}*/
}
//其它部件产生的事件则交给基类处理
return QWidget::eventFilter(target, event);
}
void DemoTestWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.fillRect(this->rect(), QColor(0, 0, 255, 50)); //QColor最后一个参数80代表背景的透明度
}
TestWidget.cpp_2
最新推荐文章于 2022-10-17 22:42:07 发布