#include "PPT.h"
#include<Windows.h>
#include <QWindow>
#include <QMouseEvent>
#include <QtGui>
#include <QMessageBox>
HHOOK keyHook = NULL;
HHOOK mouseHook = NULL;
//声明卸载函数,以便调用
void unHook();
//键盘钩子过程
LRESULT CALLBACK keyProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//在WH_KEYBOARD_LL模式下lParam 是指向KBDLLHOOKSTRUCT类型地址
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *)lParam;
if (pkbhs->vkCode == VK_F12)
{
unHook();
qApp->quit();
}
return 0;//返回1表示截取消息不再传递,返回0表示不作处理,消息继续传递
}
//鼠标钩子过程
LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
tagMSLLHOOKSTRUCT* pkbhs = (tagMSLLHOOKSTRUCT *)lParam;
qDebug() << "Hook1";
if (wParam == WM_LBUTTONDOWN || wParam == WM_LBUTTONUP)
{
//unHook();
//qApp->quit();
}
return 0;
//unHook();
//QMessageBox::information(NULL, "提示", "mouseProc", QMessageBox::Accepted);
//qApp->quit();
//return 0;
}
//卸载钩子
void unHook()
{
UnhookWindowsHookEx(keyHook);
UnhookWindowsHookEx(mouseHook);
}
//安装钩子,调用该函数即安装钩子
void setHook()
{//这两个底层钩子,不要DLL就可以全局
//底层键盘钩子
keyHook = SetWindowsHookEx(WH_KEYBOARD_LL, keyProc, GetModuleHandle(NULL), 0);
//底层鼠标钩子
mouseHook = SetWindowsHookEx(WH_MOUSE_LL, mouseProc, GetModuleHandle(NULL), 0);
}
PPT::PPT(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
pptApp = new PowerPoint::Application();
presentations = pptApp->Presentations();
if (presentations != NULL)
{
presentation = static_cast<PowerPoint::Presentation*>(presentations->querySubObject("Open(QString&)", "D:\\test.pptx"));
slideshow = static_cast<PowerPoint::SlideShowSettings*>(presentation->querySubObject("SlideShowSettings()"));
slideshow->Run();
slideShowWindow = static_cast<PowerPoint::SlideShowWindow*>(presentation->querySubObject("SlideShowWindow()"));
}
WId wid = (WId)FindWindow(L"screenClass", NULL);
//第三步:获取QWindow
QWindow *m_window;
m_window = QWindow::fromWinId(wid);
m_window->setFlags(m_window->flags() | Qt::CustomizeWindowHint | Qt::WindowTitleHint); //这边可以设置一下属性
//第四步:获取代理QWidget
m_widget = QWidget::createWindowContainer(m_window,this); //第二个参数是作为window的父类,也可以用layout,此处就不解释了
setCentralWidget(m_widget);
slideShowView = static_cast<PowerPoint::SlideShowView*>(slideShowWindow->querySubObject("View()"));
SetParent(FindWindow(L"screenClass", NULL), (HWND)(m_widget->winId()));
m_widget->setFocus();
//setHook();
}
bool PPT::eventFilter(QObject *target, QEvent *event)
{
qDebug("eventFilter");
if ((QWidget*)target == upWidget)
{
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()");
//}
slideShowView->dynamicCall("Next()");
return true;
}
}
//其它部件产生的事件则交给基类处理
return QWidget::eventFilter(target, event);
}
void PPT::onNext()
{
/*QPoint pos(403, 34);
QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QApplication::sendEvent(this, &event0);*/
slideShowView->dynamicCall("Next()");
}
// 鼠标按下事件
void PPT::mousePressEvent(QMouseEvent *event)
{
// 如果是鼠标左键按下 改变指针形状,并且存储当前指针位置与窗口位置的差值。
if (event->button() == Qt::LeftButton)
{
}
}
08-06
08-06
08-06