Keeping speech grammars up-to-date

I've been having a good conversation with some guys that are working on making it easier to program by voice using Python. Their project is called "VoiceCode" and they've been working on it for quite some time. Currently it only supports Dragon NaturallySpeaking as a speech recognizer, but I'm helping them to understand how easy it would be to port to Vista.

One issue that came up recently was: How can they keep their grammars up to date if their grammars change based on what application is running, or what the title is in any given application. I was trying to describe to them in email how they could use the SetWinEventHook method, but I wasn't being as successful describing it to them as I wanted to... So ... I just wrote about 500 lines of code for them to show them.

Then, I thought ... Hey, other people might want to see how to do this too. So I posted the code here. Let me know if you have any questions!