用于“监听”办公应用程序的NET代码(获取用户引发的事件)

时间:2021-11-01 00:00:10

I am on the verge of remaking an application for e-learning. But now I want to take this new version to a new level.

我即将重新制作电子学习申请。但现在我想将这个新版本提升到一个新的水平。

So this the scenario: a user opens up my app. He/she then chooses to be trained in one of the most common MS Office applications (Word,Excel,Outlook, etc).

所以这个场景:用户打开我的应用程序。然后,他/她选择接受最常见的MS Office应用程序(Word,Excel,Outlook等)之一的培训。

My app will give the user instructions on what to do: create a new document, type some text, turn it bold, insert a picture, etc. If done correctly the user will be awarded points. If not, demerits.

我的应用程序将向用户提供有关操作的说明:创建新文档,键入一些文本,将其粗体显示,插入图片等。如果操作正确,用户将获得积分。如果不是,那就是缺点。

But (there is always a but )for me to accomplish this I have to be able to "see" what the user is doing. I am using NET (2.0 - C# or VB, doesn't matter which). Can anyone tell how to do this? I need to get a handle to the open Office app or start a new one and then I have to listen and evaluate everything the user does.If the user does it wrong I also need to send instructions to the Office app and do it for him/her.

但是(总有一个但是)对我来说,我必须能够“看到”用户在做什么。我正在使用NET(2.0 - C#或VB,无所谓)。谁能告诉你怎么做?我需要处理打开的Office应用程序或启动一个新应用程序然后我必须倾听并评估用户所做的一切。如果用户做错了我还需要向Office应用程序发送指令并为他执行此操作/她。

Is this possible? Does anyone has some samples of code on how to do this or anything similar?

这可能吗?有没有人有一些关于如何做到这一点或类似的代码示例?

Thanks in advance

提前致谢

PS:I really wouldn't want to have a Office add on to accomplish this!

PS:我真的不想让Office添加来实现这个目标!

Edited: The reason I don't want to get into VBA is that I wanted to make sure that this was reusable to assist users in using other applications further down the road. So I wanted some way to create a listener to an application and decode the user interaction with it.

编辑:我不想进入VBA的原因是我想确保这是可重用的,以帮助用户在未来的路上使用其他应用程序。所以我想要一些方法来创建一个应用程序的监听器并解码用户与它的交互。

2 个解决方案

#1


There is actually a Windows hook designed for computer based training applications called WH_CBT and it provides notification when windows are activated, minimized, moved, resized, commands are executed, mouse/keyboard events, etc.

实际上有一个Windows钩子设计用于基于计算机的训练应用程序,称为WH_CBT,它在窗口被激活,最小化,移动,调整大小,执行命令,鼠标/键盘事件等时提供通知。

I won't lie to you though, hooking is a fairly complex topic but is certainly approachable from .NET. Have a look at the following MSDN article that explains how to use message hooking in .NET and then have a look at the two links that follow for more information about WH_CBT.

我不会骗你,挂钩是一个相当复杂的话题,但从.NET来说肯定是平易近人的。查看以下MSDN文章,该文章解释了如何在.NET中使用消息挂钩,然后查看后面的两个链接以获取有关WH_CBT的更多信息。

Cutting Edge: Windows Hooks in the .NET Framework

前沿:Windows框架中的Windows挂钩

MSDN Library: SetWindowsHookEx Function

MSDN Library:SetWindowsHookEx函数

MSDN Library: CBTProc Function

MSDN Library:CBTProc函数

#2


The automation API for Office is a COM API. You can call it from managed (.NET) code, but that just adds an extra layer and makes things considerably more complex. I've done a great deal of Office automation work using both VB/VBA and C# and while I love C# as a language, I have to say that it's much more difficult to drive Office that way. Much. (It's easy to get it to work on your machine, at least once - but don't let that fool you).

Office的自动化API是一个COM API。您可以从托管(.NET)代码中调用它,但这只会增加一个额外的层并使事情变得更加复杂。我使用VB / VBA和C#完成了大量的Office自动化工作,虽然我喜欢C#作为一种语言,但我不得不说以这种方式驱动Office要困难得多。许多。 (它很容易让它在你的机器上工作,至少一次 - 但不要让那个骗你)。

The API does allow you to trap certain events such as menu selections, command bar button clicks, window activation, document open/close, etc. You can also trap the "selection changed" event which you could theoretically use to figure out what the user is doing. But, there are a lot of direct-manipulation tasks that a user can perform that you would not be able to trap (e.g. drag-and-drop, resize a picture, etc.) and for your purposes I'd say that'd be a big problem.

API允许您捕获某些事件,例如菜单选择,命令栏按钮单击,窗口激活,文档打开/关闭等。您还可以捕获“选择已更改”事件,理论上您可以使用该事件来确定用户的内容是在做。但是,有很多直接操作任务,用户可以执行,你将无法陷阱(例如拖放,调整图片等),为了你的目的,我会说'd是个大问题。

I'd have to say I very much doubt you'd be able to do what you propose - at least, not well enough to make it seamless. And I would think that it has to be pretty bomb-proof given your user base.

我不得不说我非常怀疑你能够做你提出的建议 - 至少,不足以让它无缝化。考虑到你的用户群,我认为它必须是非常防弹的。

Sorry. :-(

#1


There is actually a Windows hook designed for computer based training applications called WH_CBT and it provides notification when windows are activated, minimized, moved, resized, commands are executed, mouse/keyboard events, etc.

实际上有一个Windows钩子设计用于基于计算机的训练应用程序,称为WH_CBT,它在窗口被激活,最小化,移动,调整大小,执行命令,鼠标/键盘事件等时提供通知。

I won't lie to you though, hooking is a fairly complex topic but is certainly approachable from .NET. Have a look at the following MSDN article that explains how to use message hooking in .NET and then have a look at the two links that follow for more information about WH_CBT.

我不会骗你,挂钩是一个相当复杂的话题,但从.NET来说肯定是平易近人的。查看以下MSDN文章,该文章解释了如何在.NET中使用消息挂钩,然后查看后面的两个链接以获取有关WH_CBT的更多信息。

Cutting Edge: Windows Hooks in the .NET Framework

前沿:Windows框架中的Windows挂钩

MSDN Library: SetWindowsHookEx Function

MSDN Library:SetWindowsHookEx函数

MSDN Library: CBTProc Function

MSDN Library:CBTProc函数

#2


The automation API for Office is a COM API. You can call it from managed (.NET) code, but that just adds an extra layer and makes things considerably more complex. I've done a great deal of Office automation work using both VB/VBA and C# and while I love C# as a language, I have to say that it's much more difficult to drive Office that way. Much. (It's easy to get it to work on your machine, at least once - but don't let that fool you).

Office的自动化API是一个COM API。您可以从托管(.NET)代码中调用它,但这只会增加一个额外的层并使事情变得更加复杂。我使用VB / VBA和C#完成了大量的Office自动化工作,虽然我喜欢C#作为一种语言,但我不得不说以这种方式驱动Office要困难得多。许多。 (它很容易让它在你的机器上工作,至少一次 - 但不要让那个骗你)。

The API does allow you to trap certain events such as menu selections, command bar button clicks, window activation, document open/close, etc. You can also trap the "selection changed" event which you could theoretically use to figure out what the user is doing. But, there are a lot of direct-manipulation tasks that a user can perform that you would not be able to trap (e.g. drag-and-drop, resize a picture, etc.) and for your purposes I'd say that'd be a big problem.

API允许您捕获某些事件,例如菜单选择,命令栏按钮单击,窗口激活,文档打开/关闭等。您还可以捕获“选择已更改”事件,理论上您可以使用该事件来确定用户的内容是在做。但是,有很多直接操作任务,用户可以执行,你将无法陷阱(例如拖放,调整图片等),为了你的目的,我会说'd是个大问题。

I'd have to say I very much doubt you'd be able to do what you propose - at least, not well enough to make it seamless. And I would think that it has to be pretty bomb-proof given your user base.

我不得不说我非常怀疑你能够做你提出的建议 - 至少,不足以让它无缝化。考虑到你的用户群,我认为它必须是非常防弹的。

Sorry. :-(