如何在自己的程序中显示一个PPT文档,并且能够自己截获对PPT操作的鼠标和键盘事件。

andersky 2004-09-06 09:28:30
就是在自己的程序中用一个窗口来打开并显示一个指定的PPT,并且能把用户对这个PPT的鼠标和键盘操作截获下来,自己再作处理。
...全文
324 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gjd111686 2005-01-10
  • 打赏
  • 举报
回复
描述在微软知识库
http://support.microsoft.com/kb/183599
gjd111686 2005-01-10
  • 打赏
  • 举报
回复
使用VC++获得Microsoft Word97应用事件
概要
这文章证明怎样使用VC++.获得微软word97应用事件。但是,在这文章中观念和代码是并非对Microsoft Word特有。 他们是适用于整个套微软office应用, 以及任何其它类似的应用程序。

更多信息
下列的步给怎样建立MFC应用,它可以捕获Microsoft Word 97 Application事件Startup(), DocumentChange()和Quit():

使用MFC AppWizard创造一个新对话框。给出项目的名字WordEvents, 接受缺省的设置.给你的对话框添加两按键,并分别命名为"Start and Setup"和"Quit and Clean Up"。

添加下列的代码到 "Start and Setup"按键的句柄:

// 检查看是否你已经启动服务器.
if(m_app.m_lpDispatch != NULL) {

AfxMessageBox("Server already started.");
return;

}

char buf[256]; // General purpose buffer.

// 打开自动化服务器.
COleException e;

if(!m_app.CreateDispatch("Word.Application.8", &e)) {

sprintf(buf, "Error on CreateDispatch(): %ld (%08lx)",e.m_sc, e.m_sc);
AfxMessageBox(buf, MB_SETFOREGROUND);
return;

}

// 通过自动化使服务器变得可见.

// I.e.: Application.Visible = TRUE

DISPID dispID;
unsigned short *ucPtr;
BYTE *parmStr;
ucPtr = L"visible";

m_app.m_lpDispatch->GetIDsOfNames(IID_NULL, &ucPtr, 1, LOCALE_USER_DEFAULT, &dispID);
parmStr = (BYTE *)( VTS_VARIANT );
m_app.InvokeHelper(dispID, DISPATCH_METHOD | DISPATCH_PROPERTYPUT, VT_EMPTY,NULL, parmStr, &COleVariant((short)TRUE));

// 事件获得.

// {000209F7-0000-0000-C000-000000000046}

static const GUID IID_IWord8AppEvents = {0x000209f7,0x000,0x0000,{0xc0,0x00,0x0,0x00,0x00,0x00,0x00,0x46 } };

// 建立事件步骤

// 1. 得到服务器的IConnectionPointContainer接口.
// 2. 调用IConnectionPointContainerFindConnectionPoint()寻找到希望获得的接口
// 3. 调用IConnectionPoint::Advise()

HRESULT hr;

// 得到服务器的IConnectionPointContainer接口.
IConnectionPointContainer *pConnPtContainer;
hr = m_app.m_lpDispatch->QueryInterface(IID_IConnectionPointContainer,(void **)&pConnPtContainer);
ASSERT(!FAILED(hr));

// 为使你感兴趣的事件找到联系点.
hr = pConnPtContainer->FindConnectionPoint(IID_IWord8AppEvents,&m_pConnectionPoint);
ASSERT(!FAILED(hr));

// 得到你的事件实现的IUnknown界面.
LPUNKNOWN pUnk = m_myEventSink.GetInterface(&IID_IUnknown);
ASSERT(pUnk);

// 建立advisory联系!
hr = m_pConnectionPoint->Advise(pUnk, &m_adviseCookie);
ASSERT(!FAILED(hr));

// 释放IConnectionPointContainer
pConnPtContainer->Release();

下面是"Quit and Clean Up"按钮的处理句柄代码:

// 如果你已启动服务器.

if(m_app.m_lpDispatch == NULL) {

AfxMessageBox("You haven't started the server yet.");

return;

}

m_pConnectionPoint->Unadvise(m_adviseCookie);

// 告诉服务器放弃.

// Application.Quit()

DISPID dispID; // Temporary DISPID

unsigned short *ucPtr; // Temporary name holder

ucPtr = L"quit";

m_app.m_lpDispatch->GetIDsOfNames(

IID_NULL, &ucPtr, 1, LOCALE_USER_DEFAULT, &dispID

);

m_app.InvokeHelper(dispID, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);

// 释放应用对象.
m_app.ReleaseDispatch();

打开MFC ClassWizard (CTRL+W),加入一个源自CCmdTarget的新类MyEventSink。按下面的顺序加入新方法:

void Startup()
void Quit()
void DocumentChange()

在MyEventSink.cpp中,我们会看到下面的代码:

void MyEventSink::Startup() { AfxMessageBox("MyEventSink::Startup() called."); }
void MyEventSink::Quit() { AfxMessageBox("MyEventSink::Quit() called.");}
void MyEventSink::DocumentChange(){ AfxMessageBox("MyEventSink::DocumentChange() called.");}

打开你的MyEventSink.cpp文找到IID_IMyEventSink声明. ClassWizard为你的界面产生一新的随机GUID, 但是因为你执行一已有GUID的特有接口,所以需要进行如下修改:

static const GUID IID_IMyEventSink = {0x000209f7,0x000,0x0000,{0xc0,0x00,0x0,0x00,0x00,0x00,0x00,0x46}};

给你的在WordEventsDlg.h中WordEventsDlg类添加下列的公共成员变量:

COleDispatchDriver m_app;
IConnectionPoint *m_pConnectionPoint;
DWORD m_adviseCookie;
MyEventSink m_myEventSink;

WordEventsDlg.h中加入下面声明:

#include "MyEventSink.h"

打开文件MyEventSink.h和找出声明的destructor;它将如下出现:

// Implementation
protected:
virtual ~MyEventSink();

在"Protected"之上写出声明:

virtual ~MyEventSink();

// Implementation
protected:
// virtual ~MyEventSink(); // 或者这行可以删除.

最后,确保OLE/COM库有机会预置.正好在你的"start and setup"按键的前面添加下列的代码.这个创造全局类。初始化函数会初始化OLE/COM库。

// Ole初始化类
class OleInitClass {

public:

OleInitClass() { OleInitialize(NULL);}
~OleInitClass() { OleUninitialize();}

};

OleInitClass g_OleInitClass;

运行下面的程序你会发现当你新建文档的时候会有一个菜单弹出。在创建事件获得函数时请按顺序进行,因为word中的这三个事件函数分别对应DISPIDs 1, 2和3,如果用户按顺序创建,则不需要修改。如果象excel中一样,事件不是按顺序的,则需要人工添加dispid号。
张海霖 2005-01-10
  • 打赏
  • 举报
回复
可以阿,记录相对屏幕的位置再转换
andersky 2004-09-08
  • 打赏
  • 举报
回复
没有人知道吗???
andersky 2004-09-06
  • 打赏
  • 举报
回复
最好是使用 C#来写。

5,139

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧