About the Custom Root Object (Style Gallery) Sample
[C#]
clsGxStyleView.cs
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using ESRI.ArcGIS.Catalog; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.ADF.CATIDs; using ESRI.ArcGIS.CatalogUI; namespace CustomRootObject_CS { [Guid("0ea89e53-2d0c-4b62-9de7-50a43414a92e")] [ClassInterface(ClassInterfaceType.None)] [ProgId("CustomRootObject_CS.clsGxStyleView")] public class clsGxStyleView : ESRI.ArcGIS.CatalogUI.IGxView { #region COM Registration Function(s) [ComRegisterFunction()] [ComVisible(false)] static void RegisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType); // // TODO: Add any COM registration code here // } [ComUnregisterFunction()] [ComVisible(false)] static void UnregisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType); // // TODO: Add any COM unregistration code here // } #region ArcGIS Component Category Registrar generated code /// <summary> /// Required method for ArcGIS Component Category registration - /// Do not modify the contents of this method with the code editor. /// </summary> private static void ArcGISCategoryRegistration(Type registerType) { string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID); GxPreviews.Register(regKey); } /// <summary> /// Required method for ArcGIS Component Category unregistration - /// Do not modify the contents of this method with the code editor. /// </summary> private static void ArcGISCategoryUnregistration(Type registerType) { string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID); GxPreviews.Unregister(regKey); } #endregion #endregion #region Member Variables private IGxApplication m_pApp; private IGxCatalog m_pCatalog; private clsGxStyleGalleryItem m_pItem; private FrmGxStyleView frmGxStyleView = new FrmGxStyleView(); //Subscribe to the events coming from the GxSelection. private GxSelection m_pSelection; #endregion public clsGxStyleView() : base() { } public void PreviewItem(long hDC, tagRECT r) { if (m_pItem == null) return; m_pItem.PreviewItem((Int32)hDC, r); } private void m_pSelection_OnSelectionChanged(IGxSelection Selection, ref object initiator) { Refresh(); frmGxStyleView.RefreshView(); } #region IGxView Implementations public void Activate(ESRI.ArcGIS.CatalogUI.IGxApplication Application, ESRI.ArcGIS.Catalog.IGxCatalog Catalog) { m_pApp = Application; m_pCatalog = Catalog; m_pSelection = (GxSelection)Catalog.Selection; m_pSelection.OnSelectionChanged += new IGxSelectionEvents_OnSelectionChangedEventHandler(m_pSelection_OnSelectionChanged); frmGxStyleView.GxStyleView = this; Refresh(); } public bool Applies(ESRI.ArcGIS.Catalog.IGxObject Selection) { return Selection is clsGxStyleGalleryItem; } public ESRI.ArcGIS.esriSystem.UID ClassID { get { ESRI.ArcGIS.esriSystem.UID pUID = null; pUID = new UID(); pUID.Value = "CustomRootObject_CS.clsGxStyleView"; return pUID; } } public void Deactivate() { frmGxStyleView.GxStyleView = null; m_pApp = null; m_pCatalog = null; } public ESRI.ArcGIS.esriSystem.UID DefaultToolbarCLSID { get { return null; } } public string Name { get { return "Style"; } } public void Refresh() { IGxObject pSelection = null; pSelection = m_pCatalog.SelectedObject; if (pSelection is clsGxStyleGalleryItem) m_pItem = (clsGxStyleGalleryItem) pSelection; else m_pItem = null; } public bool SupportsTools { get { return false; } } public void SystemSettingChanged(int flag, string section) { // TODO: Add clsGxStyleView.SystemSettingChanged implementation } public int hWnd { get { return (Int32) frmGxStyleView.picStylePreview.Handle; } } #endregion } }
[Visual Basic .NET]
clsGxStyleView.vb
Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.Catalog Imports ESRI.ArcGIS.CatalogUI Imports ESRI.ArcGIS.ADF.CATIDs Imports System.Runtime.InteropServices <ComClass(clsGxStyleView.ClassId, clsGxStyleView.InterfaceId, clsGxStyleView.EventsId), _ ProgId("CustomRootObjectVBNET.clsGxStyleView")> _ Public Class clsGxStyleView Implements ESRI.ArcGIS.CatalogUI.IGxView #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" ''' <summary> ''' Required method for ArcGIS Component Category registration - ''' Do not modify the contents of this method with the code editor. ''' </summary> Private Shared Sub ArcGISCategoryRegistration(ByVal registerType As Type) Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID) GxPreviews.Register(regKey) End Sub ''' <summary> ''' Required method for ArcGIS Component Category unregistration - ''' Do not modify the contents of this method with the code editor. ''' </summary> Private Shared Sub ArcGISCategoryUnregistration(ByVal registerType As Type) Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID) GxPreviews.Unregister(regKey) End Sub #End Region #End Region #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 = "b12f0fcd-0ff9-49d3-85c3-81329b2bafd1" Public Const InterfaceId As String = "010f70e3-107e-4a3c-83e5-eb8a3dfac558" Public Const EventsId As String = "5a92b1a5-e996-4758-9e2f-c0ca49d2f08f" #End Region ' 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. #Region "Member Variables" Private m_pApp As IGxApplication Private m_pCatalog As IGxCatalog Private m_pItem As clsGxStyleGalleryItem Private frmGxStyleView As New FrmGxStyleView 'Subscribe to the events coming from the GxSelection. Private WithEvents m_pSelection As GxSelection #End Region Public Sub New() MyBase.New() End Sub Public Sub PreviewItem(ByVal hDC As Long, ByVal r As tagRECT) If m_pItem Is Nothing Then Exit Sub m_pItem.PreviewItem(hDC, r) End Sub Private Sub m_pSelection_OnSelectionChanged(ByVal Selection As IGxSelection, ByRef initiator As Object) Handles m_pSelection.OnSelectionChanged Refresh() frmGxStyleView.RefreshView() End Sub Public Sub Activate(ByVal Application As ESRI.ArcGIS.CatalogUI.IGxApplication, ByVal Catalog As ESRI.ArcGIS.Catalog.IGxCatalog) Implements ESRI.ArcGIS.CatalogUI.IGxView.Activate m_pApp = Application m_pCatalog = Catalog m_pSelection = Catalog.Selection frmGxStyleView.GxStyleView = Me Refresh() End Sub Public Function Applies(ByVal Selection As ESRI.ArcGIS.Catalog.IGxObject) As Boolean Implements ESRI.ArcGIS.CatalogUI.IGxView.Applies Applies = TypeOf Selection Is clsGxStyleGalleryItem End Function Public ReadOnly Property ClassID1() As ESRI.ArcGIS.esriSystem.UID Implements ESRI.ArcGIS.CatalogUI.IGxView.ClassID Get Dim pUID As IUID pUID = New UID pUID.Value = "CustomRootObjectVBNET.clsGxStyleView" ClassID1 = pUID End Get End Property Public Sub Deactivate() Implements ESRI.ArcGIS.CatalogUI.IGxView.Deactivate frmGxStyleView.GxStyleView = Nothing m_pApp = Nothing m_pCatalog = Nothing End Sub Public ReadOnly Property DefaultToolbarCLSID() As ESRI.ArcGIS.esriSystem.UID Implements ESRI.ArcGIS.CatalogUI.IGxView.DefaultToolbarCLSID Get DefaultToolbarCLSID = Nothing End Get End Property Public ReadOnly Property hWnd() As Integer Implements ESRI.ArcGIS.CatalogUI.IGxView.hWnd Get hWnd = frmGxStyleView.picStylePreview.Handle End Get End Property Public ReadOnly Property Name() As String Implements ESRI.ArcGIS.CatalogUI.IGxView.Name Get Name = "Style" End Get End Property Public Sub Refresh() Implements ESRI.ArcGIS.CatalogUI.IGxView.Refresh Dim pSelection As IGxObject pSelection = m_pCatalog.SelectedObject If TypeOf pSelection Is clsGxStyleGalleryItem Then m_pItem = pSelection frmGxStyleView.RefreshView() Else m_pItem = Nothing End If End Sub Public ReadOnly Property SupportsTools() As Boolean Implements ESRI.ArcGIS.CatalogUI.IGxView.SupportsTools Get SupportsTools = False End Get End Property Public Sub SystemSettingChanged(ByVal flag As Integer, ByVal section As String) Implements ESRI.ArcGIS.CatalogUI.IGxView.SystemSettingChanged End Sub End Class