Visio 2003 Developer's Survival Pack Tools and Samples

Chapter 20: Events and Notifications
Visio 2003 DSP home   This page

Overview

A collection of samples pertaining to events and notifications of various kinds. It may be very informative to try these samples in conjunction with the Events Browser.

Files

Filename Description Installation
SimplePageWithEvent.vdx Open the VBA window and inspect the ThisDocument module. Run the PageEvents_Init procedure to initialize events. (To do this, place cursor in the procedure and click the Run arrow.) Now drop shapes on the drawing page (for example using the Rectangle tool). Observe the reports written to the VBA Immediate window by the APage_ShapeAdded procedure.  
EventListAddRunAddon.vdx Open the VBA window and inspect the ThisDocument module. Run the HookupAShape procedure to set up an event for cell changes on the one shape on the drawing. Now, on the drawing select the one sample shape and try changing something that will affect one or more cells, such as adjusting the width. Observe how this causes Visio to call the Addon executable app specified in HookupAShape, possibly multiple times. Before running this sample, you will need to perform the simple installation of the ReflectArgs sample application. See the sample folder for Chapter 23.
SimpleEventListAdd.vdx Basically the same demo as EventListRunAddon, except that here the Hookup procedure creates an event for Application.  
SimpleEventSink.vdx Open the VBA window and inspect the ThisDocument module. Run the HookupEvent procedure to set up an event on Application for cell changes in any drawing. Now, on the drawing select the one sample shape and try changing something that will affect one or more cells, such as adjusting the width. Observe how this causes Visio to call ASimpleEventSink.IVisEventProc_VisEventProc, which writes messages to the VBA Immediate window.   
WithEventsUsingClassModule.vdx This sample demonstrates several topics:
  • ThisDocument includes a Document_DocumentOpened event which hooks initializes events, in this case calling ShapeEventMgr_Init to set up events on one or more shapes.
  • The hooking up and unhooking of events is centralized in the ShapeEventMgr module.
  • Events are handled using the AddAdvise and EventSink strategy (using the CShapeEventCatcher class)..

When you open this document, (assuming you enable macros) events will be set up automatically. At that point you can adjust the width or height of the sample shape, and observe this firing CShapeEventCatcher.AShape_CellChanged which writes reports to the Immediate window.

 
EventSinkForwarding.vdx A variation on the EventSink theme, which can make for tidier code.  In previous EventSink examples, the actual event-handling code is placed in the EventSink class itself. The problem with this is that when handling a variety of events on a variety of objects, a project can end up with a proliferation of EventSink classes which are hard to maintain.

In the approach demonstrated here, only a single generic CEventSinkForwarder class is needed. Objects created from this class forward ("delegate") event calls to their respective owner modules. This allows the specific event-response code to reside in the same module that created the event sink in the first place -- potentially much more orderly.

 
EventSinkWithFilters.vdx As with several of the samples above, start by opening the VBA window and ThisDocument module, and run the HookupEvent procedure. Verify that this did something useful by resizing the one shape on the drawing, and observe the reports to the Immediate window. Now try running the various SetEventFilterXxx procedures, and observe the events which now do or don't result in event reports. You'll have to inspect each SetEventFilter procedure to see which events are included or excluded in each case. You can also try the corresponding procedures to read the event filters.

The Events Browser is especially useful with this sample. Note that the event in this sample is on Application, so you can set Events Browser to survey only down to the level of Application, which is very quick.

 
     

Operation

Suggestions on how to operate are found on the drawing..


Article Created: 2003-09-01  Last edit: Last edit: 03-10-13 Graham Wideman
Go to:
  DiagramAntics.com