Select to view content in your preferred language

Close Dockable Window BEFORE close application

3074
2
09-08-2011 05:45 AM
AlexandraFairbarns
Deactivated User
Good afternoon/morning to all,

I want to be able to close my dockable window (opened via a toolbar button) every time the application (not document) is closed. At the moment, if the dockable window is open when arcmap is closed , when arcmap is re-opened the dockable window loads itself again. This is rather irritating for my client.

I was wishing to do this through my event listening extension i have created in my add-in project, which is persistent. I have been able to handle an ondocumentclose() and onshutdown() event in this, however only the onshutdown() will fire when the application is closed (i would have thought that since its closing the document before closing the application it would do the ondocumentclose() event first?). Alas i cannot figure out how to access the document before the application is closed.

I cant imagine that no-one else has not wanted to do this, so it would be great if someone had the answer!

Thank You

Alex
0 Kudos
2 Replies
AlexanderGray
Honored Contributor
Have you looked at IDocumentEvents.BeforeCloseDocument?  You can also close the dockwin on opendocument, at the start of the session instead of at the end.
0 Kudos
AlexandraFairbarns
Deactivated User
Thank You, Yes, but ends up dont need to do it that way, noticed that the application wasnt hooking correctly so the onclosedocument() DOES now fire BEFORE onshutdown(). However, it does remove the dockable window every time you open a new map (i.e. you then have to click it on again). For anyone elses benefit i am including my code (amalgamation from arcgis objects help).. Note that this was implemented on an extension, in a standard module i have an open/close event that shows/doesnt shown the dockable window depending on if the document is to be closed.

 

Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Framework

Public Class SSIM_EventListening

Inherits ESRI.ArcGIS.Desktop.AddIns.Extension
Private m_docEvents As ESRI.ArcGIS.ArcMapUI.IDocumentEvents_Event

Public Sub New()

End Sub

Protected Overrides Sub OnStartup()

WireDocumentEvents()

End Sub

Protected Overrides Sub OnShutdown()
'You can remove handlers here, but not working here for me
End Sub

Private Sub WireDocumentEvents()

Dim app As ESRI.ArcGIS.Framework.IApplication = CType(Hook, ESRI.ArcGIS.Framework.IApplication)

If app Is Nothing Then Return

'Handle Document events
Dim doc As ESRI.ArcGIS.Framework.IDocument = app.Document

m_docEvents = CType(doc, IDocumentEvents_Event)
AddHandler m_docEvents.CloseDocument, AddressOf OnCloseDocument

End Sub

Private Sub OnCloseDocument()

Call openclose()

End Sub
 
End Class
[/CODE

Happy programming

Alex
0 Kudos