PDA

View Full Version : Sleeper: Creating custom event



johnske
08-10-2005, 02:38 AM
Hi,

I want opening or activating the VBE (main) window to be a custom event that triggers some code... any ideas?

Regards,
John

Killian
08-12-2005, 07:29 AM
Hi John,

I had a think about this... there simply isn't an application event or anything I can find in the object model to force this. I considered how a COM addin for the VBE might help but I believe that it would be loaded with the Excel app, rather than when the VBE was first activated, so I can't see that working. That's not to say it isn't possible, just very fiddly.
My current thinking is, that if it can't be done at application level, then it's time to roll out a Win API function or two...
Windows is message based, rather that event driven, so I order to do this, you'd need to "hook" into the target window (VBE main) and fire some code on any Activate messages that are sent to it.
The SetWindowsHookEx function looks promising. There's a "WH_CBT" HookID parameter designed for computer-based training apps that should be useful - I think the key will be trapping the VBE Activate message without producing too much of an overhead on everything else that's going on (it looks like you can associate the hook with a specific process thread, so that should be OK)
I have to admit, it's a bit more challenging than I was expecting - if I get the chance I'll try to get my head around it at some stage