| |
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports ESRI.ArcGIS.ADF.BaseClasses
Imports ESRI.ArcGIS.ADF.CATIDs
Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.ArcMapUI
Imports System.Windows.Forms
<ComClass(RemoveAllLayersCmd.ClassId, RemoveAllLayersCmd.InterfaceId, RemoveAllLayersCmd.EventsId), _
ProgId("PSRCTools.RemoveAllLayersCmd")> _
Public NotInheritable Class RemoveAllLayersCmd
Inherits BaseCommand
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "5cc3bcf2-27da-459c-9567-2038b9849a3d"
Public Const InterfaceId As String = "c8b6c42d-26b1-4227-bb82-65a9bc625148"
Public Const EventsId As String = "8d2400e1-67f3-4699-8b47-3df98903522b"
#End Region
#Region "COM Registration Function(s)"
<ComRegisterFunction(), ComVisibleAttribute(False)> _
Public Shared Sub RegisterFunction(ByVal registerType As Type)
' Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType)
'Add any COM registration code after the ArcGISCategoryRegistration() call
End Sub
<ComUnregisterFunction(), ComVisibleAttribute(False)> _
Public Shared Sub UnregisterFunction(ByVal registerType As Type)
' Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType)
'Add any COM unregistration code after the ArcGISCategoryUnregistration() call
End Sub
#Region "ArcGIS Component Category Registrar generated code"
Private Shared Sub ArcGISCategoryRegistration(ByVal registerType As Type)
Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
MxCommands.Register(regKey)
End Sub
Private Shared Sub ArcGISCategoryUnregistration(ByVal registerType As Type)
Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
MxCommands.Unregister(regKey)
End Sub
#End Region
#End Region
Private m_ActiveViewEventsItemDeleted As ESRI.ArcGIS.Carto.IActiveViewEvents_ItemDeletedEventHandler
Private m_application As IApplication
Private pMxdoc As IMxDocument
Private pAView As ESRI.ArcGIS.Carto.IActiveView
Private pMap As ESRI.ArcGIS.Carto.IMap
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
' TODO: Define values for the public properties
MyBase.m_category = "" 'localizable text
MyBase.m_caption = "Remove All Layers" 'localizable text
MyBase.m_message = "Removes All Layers" 'localizable text
MyBase.m_toolTip = "Click to Remove All Layers" 'localizable text
MyBase.m_name = "Remove All Layers" 'unique id, non-localizable (e.g. "MyCategory_ArcMapCommand")
Try
'TODO: change bitmap name if necessary
m_bitmap = New Bitmap(Me.GetType.Assembly.GetManifestResourceStream("PSRCTools.layers_check_off.bmp"))
'Dim bitmapResourceName As String = Me.GetType().Name + ".bmp"
'MyBase.m_bitmap = New Bitmap(Me.GetType(), bitmapResourceName)
Catch ex As Exception
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap")
End Try
End Sub
Public Overrides Sub OnCreate(ByVal hook As Object)
If Not hook Is Nothing Then
m_application = CType(hook, IApplication)
'Disable if it is not ArcMap
If TypeOf hook Is IMxApplication Then
MyBase.m_enabled = True
Else
MyBase.m_enabled = False
End If
End If
pMxdoc = m_application.Document
pMap = pMxdoc.FocusMap
pAView = pMap
WireEvents()
End Sub
Public Overrides Sub OnClick()
'If MessageBox.Show("Are you sure you want to remove all layers from the Table of Contents?", "Remove all layers?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
'Dim LayersOn As Boolean = False
If CheckForLayers(pMap) = False Then
MessageBox.Show("There are no Layers to Remove", "No Layers in the TOC", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If MessageBox.Show("Are you sure you want to remove all layers from the Table of Contents?", "Remove all layers?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
pMap.ClearLayers()
pMxdoc.UpdateContents()
pAView.Refresh()
Else
Exit Sub
End If
End Sub
Public Sub WireEvents()
m_ActiveViewEventsItemDeleted = New ESRI.ArcGIS.Carto.IActiveViewEvents_ItemDeletedEventHandler(AddressOf OnActiveViewEventsItemDeleted)
AddHandler CType(pMap, ESRI.ArcGIS.Carto.IActiveViewEvents_Event).ItemDeleted, m_ActiveViewEventsItemDeleted
End Sub
Private Sub OnActiveViewEventsItemDeleted(ByVal Item As Object)
MessageBox.Show("Item Deleted")
End Sub
End Class |