Automation Events


If your macro or add-in needs to be notified when a certain event occurs, various event objects are supported in all the automation object categories previously discussed. There are events for windows, events for editors, events for projects, and so on. For every event supported by the IDE, a corresponding class in the automation model allows you to hook the event and take action if the event is raised. The event objects tree is rooted in the DTE.Events property, as depicted in Figure 10.10.

Figure 10.10. Event types.


Because events are handled differently depending on whether you are working with code in an add-in or code in a macro, we will wait until the next chapter to cover the details of handling events. The basic premise, however, is fairly simple: You obtain a reference to the event object that you are interested in and then write an event handler that responds to one of that object's published events.

This code, for instance, is how you might handle the "build complete" event from inside a Visual Basic add-in:

Dim WithEvents bldevents As BuildEvents bldevents = DTE.Events.BuildEvents


After instantiating a BuildEvents object, you now have to write the actual event handler:

Private Sub bldevents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, _      ByVal Action As EnvDTE.vsBuildAction) Handles bldevents.OnBuildDone         ' Code to handle the event goes here     End Sub





Microsoft Visual Studio 2005 Unleashed
Microsoft Visual Studio 2005 Unleashed
ISBN: 0672328194
EAN: 2147483647
Year: 2006
Pages: 195

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net