Getting document before closed event via hook in Engine and ArcMap apps

1319
0
05-19-2010 08:00 AM
MichaelDorais
New Contributor III
I have all the basics down and can create custom extensions and custom toolbars that work with the custom extension and have it work in both ArcMap and and an Engine map control application.

The problem I have is that I want to be able to capture when the map and/or its document is about to close or change.  I have not been able to find a consistent way to do this that will work in both Engine map control applications and ArcMap.  In ArcMap there are classes and interfaces available only in desktop that do the trick and are simple because the ArcMap application always work with a single document at a time (it is basically an SDI app providing multiple views, one-at-a-time of the same document).   However my Engine map control application is MDI with multiple forms, each containing there own map control and associated document.

In ArcMap the hook is an instance of an Application class that implements IApplication and IMxApplication.  Through IApplication it is possible to navigate to the Document property which would be an instance of an MxDocument which implements IDocument and IDocumentEvents.  IDocumentEvents provides what I was interested in: The BeforeCloseDocument event. 
This is not accessible in an ArcGIS Engine map control application.

Is there a best practices way already established for a writer of toolbars, with or without associated extensions, to be able to receive an event BEFORE the map document closes also in an Engine map control application?

One possibility that I don't like too much and don't know if it will work is to create a class that derives from the Engine toolbar control class and also implements IApplication.  I'm not sure how well deriving will go (I may have to contain or aggregate it), but there is still the question of availability of the interfaces that are defined in Framework, ArcMapUI.  If the application is running on a machine that only has a ArcGIS Engine installed and only has an ArcGIS Engine license, will these interfaces be available: IApplication, IDocument, IDocumentEvents. 
A positive about this approach would be that the writer of the toolbar would just need to attempt to QI the hook passed in on OnCreate to IApplication, navigate to Document and QI It to IDocumentEvents and it would work in both ArcMap and an ArcGIS Engine control application.  But fully implementing the interfaces would be too much work and require crippling it to make it practical.


I know I can solve this for our particular implementation, but it will require creating a new shared Interface type and a defined way check for the writer of a toolbar/tool/extension to check for it if the tool is running with a map control instead of with the IApplication hook.  That would require an extension writer to know about this new shared interface we develop, have access to its type definition and or dll, and while their extension would work in ArcMap if they write it to behave properly when running in ArcMap, it would probably only work properly in our engine map control application.

I am currently developing with ArcGIS ENgine 9.3.1 using Microsoft .Net. 3.5 with Visual Studio 2008.
0 Kudos
0 Replies