views:

210

answers:

2

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).

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.

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!

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.

+2  A: 

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).

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.

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. :-(

Gary McGill
Nothing to be sorry about:) Not your fault. Thanks for the input but I still have hope that there may be another way around this:)If I find it I shall post it.
Antonio Louro
Guess you will getting the bounty points:) No one seems to know how to solve this one...
Antonio Louro
Seems I was wrong:) Thank you for the input, though.
Antonio Louro
+1  A: 

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.

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.

Cutting Edge: Windows Hooks in the .NET Framework

MSDN Library: SetWindowsHookEx Function

MSDN Library: CBTProc Function

Josh Einstein
I never expected it to be easy:) Thank you for your answer. This seems to be the way to go!
Antonio Louro