You are here: > ESRI Forums > arcgis engine forums > Thread Replies

ArcGIS Engine Forums

ArcGIS Engine: Controls forum

IGxDialog   Charles Tilly Nov 05, 2004
Re: IGxDialog   Rob Dunfey Nov 08, 2004
Re: IGxDialog   Charles Tilly Nov 08, 2004
Re: IGxDialog   cyril cherian Jul 25, 2005
Re: IGxDialog   cyril cherian Jul 27, 2005
Re: IGxDialog   Charles Tilly Aug 01, 2005
Re: IGxDialog   cyril cherian Aug 23, 2005
Re: IGxDialog   Charles Tilly Aug 23, 2005
Re: IGxDialog   Valeria Andronaco Dec 23, 2009
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject IGxDialog 
Author Charles Tilly 
Date Nov 05, 2004 
Message Anyone have a way to provide a dialog to users for adding layers and other data?

Thanks so much 
  Regards,

Chuck T 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: IGxDialog 
Author Rob Dunfey 
Date Nov 08, 2004 
Message This code demonstrates the principle. It goes behind the click event of a command button in VB6 and works with a MapControl.

Hope it helps,

Rob

********
Apologies, as has been pointed out, this script will require a desktop install. 
 
Dim pDialog As IGxDialog
  Set pDialog = New GxDialog
  Dim pFilter As New GxFilterDatasets
  Set pDialog.ObjectFilter = pFilter
  Dim pEnumGX As IEnumGxObject
  Dim blnflg As Boolean
  
  pDialog.Title = "Add Layer"
  pDialog.AllowMultiSelect = True
  pDialog.StartingLocation = "C:\Program Files\ArcGIS\DeveloperKit\samples\data\arcgis_engine_developer_guide\data"
  blnflg = pDialog.DoModalOpen(0, pEnumGX)
  
  If blnflg = False Then Exit Sub
  
  'Reset Enum so we are at the start
  pEnumGX.Reset

  'Get first object
  Dim pGXObject As IGxObject
  Set pGXObject = pEnumGX.Next
  
  Do While Not pGXObject Is Nothing

    'Query interface for IGxDataset interface
    Dim pDataSet As IDataset
    Dim pFeatureLayer As IFeatureLayer
    Dim pRasterLayer As IRasterLayer
    Dim pLayer As ILayer
    Dim pGxDataset As IGxDataset
    
    If TypeOf pGXObject Is IGxDataset Then
      Set pGxDataset = pGXObject
      Set pDataSet = pGxDataset.Dataset
        If TypeOf pDataSet Is IFeatureClass Then
          Set pFeatureLayer = New FeatureLayer
          Set pFeatureLayer.FeatureClass = pDataSet
          pFeatureLayer.Name = pDataSet.Name
           Set pLayer = pFeatureLayer
        ElseIf TypeOf pDataSet Is IRasterDataset Then
          Set pRasterLayer = New RasterLayer
          pRasterLayer.CreateFromDataset pDataSet
          pRasterLayer.Name = pDataSet.Name
          Set pLayer = pRasterLayer
        Else
          MsgBox "You must select a feature class or raster.", vbOKOnly, "Add Layer"
          Exit Sub
        End If
      MapControl1.AddLayer pLayer, MapControl1.LayerCount
    Else
      MsgBox "You must select a feature class or raster.", vbOKOnly, "Add Layer"
      Exit Sub
    End If
    Set pGXObject = pEnumGX.Next
    
  Loop
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: IGxDialog 
Author Charles Tilly 
Date Nov 08, 2004 
Message Thanks Rob. I guess I should have also mentioned that I was trying to do this as a custom command that would be added to the ToolbarControl. So because of that the code needs to be extremely generic and can't make references to MapControl. I was having a booger of a time getting the layers I selected from the dialog to load in the map control. As usual it turned out to be something simple, but without knowing how it was supposed to be done I was pretty much stabbing in the dark.

I did manage to finally come up with something that works in C# for anyone that is interested. I have included just the core functionality of the command button with no error trapping or anything else. If you compile this code as is (you may need to change the GUIDs, plus provide a legitimate path to a bitmap image) then the Add Data button will automatically show up in the CommandToolControl properties dialog and you can then add it as a command button.

If anyone comes up with something more clever then please share. 
 
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Utility.BaseClasses;
using ESRI.ArcGIS.Utility.CATIDs;
using ESRI.ArcGIS.ControlCommands;
using ESRI.ArcGIS.CatalogUI;
using ESRI.ArcGIS.Catalog;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.MapControl;


namespace OurCustomCommands
{
	/// <summary>
	/// Provide a browser dialog that will allow users to add additional layers
	/// </summary>
	//[ClassInterface(ClassInterfaceType.None)]
	[Guid("05a2625a-5b7d-405b-a432-983090f123a6")]
	public sealed class AddData : BaseCommand
	{
		private IHookHelper myHookHelper;
		private IGxDialog pDialog;
		private Bitmap pBitmap;
		
		// Needed to clear up the Hbitmap unmanaged resource
		[System.Runtime.InteropServices.DllImport("gdi32.dll")]
		static extern bool DeleteObject(IntPtr hObject);

		public AddData()
		{
			myHookHelper = new HookHelperClass();
			pBitmap = new Bitmap(this.GetType().Assembly.GetManifestResourceStream("OurCustomCommands.AddData.bmp"));

			this.m_caption = "Add Data";
			this.m_category = "Custom Controls";
			this.m_message = "Provides browser for selecting layers to add";
			this.m_toolTip = "Add Data";
			this.m_name = "AddData";
			this.m_bitmap = pBitmap;
		}
		
		~AddData()	//CLASS DESTRUCTOR
		{
			// Must de-allocate the UI resources with Windows.DeleteObject
			if (pBitmap.GetHbitmap().ToInt32() != 0)
			{
				DeleteObject(pBitmap.GetHbitmap());
			}
			Marshal.ReleaseComObject(myHookHelper);
		}
	
		public override void OnClick()
		{
			pDialog = new GxDialogClass();
			pDialog.Title = "Add Data To Map";
			pDialog.AllowMultiSelect = true;
			
			// AN UNDOCUMENTED WAY OF SETTING THIS PROPERTY SINCE
			// THE DOCUMENTED WAY DOESN'T WORK IN C#
			object pPath = @"C:\Program Files\ArcGIS\DeveloperKit\samples\data\arcgis_engine_developer_guide\data";
			pDialog.set_StartingLocation(ref pPath);
			
			IGxObjectFilter pGxFilter;
			pGxFilter = new GxFilterFeatureClassesClass();
			pDialog.ObjectFilter = pGxFilter;

			IEnumGxObject enumGObj;
						
			if ((bool)pDialog.DoModalOpen(0, out enumGObj))
			{
				IFeatureLayer pFLayer;
				ILayer pLayer;
				IGxDataset pGxDataset;

				enumGObj.Reset();
				pGxDataset = (IGxDataset)enumGObj.Next();
				
				while(pGxDataset!=null)
				{
					pFLayer = new FeatureLayerClass();
					
					pFLayer.FeatureClass = (IFeatureClass)pGxDataset.Dataset;
					pFLayer.Name = pFLayer.FeatureClass.AliasName;
					
					pLayer = pFLayer;

					myHookHelper.ActiveView.FocusMap.AddLayer(pLayer);

					pGxDataset = (IGxDataset)enumGObj.Next();
				}
				myHookHelper.ActiveView.Refresh();
			}
		}
	
		public override void OnCreate(object hook)
		{
			myHookHelper.Hook = hook;
		}

		#region "Component Category Registration"
		[ComRegisterFunction()]
		static void Reg(string regKey)
		{
			ControlsCommands.Register(regKey);
		}

		[ComUnregisterFunction()]
		static void Unreg(string regKey)
		{
			ControlsCommands.Unregister(regKey);
		}
		#endregion


	}
}
 
  Regards,

Chuck T 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: IGxDialog 
Author cyril cherian 
Date Jul 25, 2005 
Message I am bit confused by seeing this thread in ArcGIS Engine forum. Can we use IGXDialog in ArcEngine, as it is under CatalogUI namespace. My impression is that it is only supported by ArcGIS desktop.
Am I interpreting something wrong?

Thanks
Cyril
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: IGxDialog 
Author cyril cherian 
Date Jul 27, 2005 
Message I tested this tool. This will work great with MapControl on a machine that has ArcGIS installed.
But it cannot work on a machine that do not have ArcGIS installed.
Can anyone give me any idea how I can create a ADDData dialog that mimic ArcGIS AddData dialog.
Any idea when ESRI will provide on Arc Engine Community. They have provided it on the properties dialog of MapControl. I don't know why they did not provide it with the toolkit.

Thanks
Cyril
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: IGxDialog 
Author Charles Tilly 
Date Aug 01, 2005 
Message I don't know if your claim is entirely accurate. Users need to have the ArcEngine runtime on their boxes to run any application using ArcEngine. To my knowledge this should work on a machine with just the runtime installed. I got pulled in on a different project soon after I posted this code so I don't really know for sure if this is a true statement. But my impression is that the runtime is all that is necessary, which you need anyway.

With respect to your last question, I did pose the question to some of the ESRI ArcEngine developers at the BP conference back in Feb. and they all pretty much gave the same lame answer ("we didn't think it was that important of a control"). They did, however, mention that it would/should be available in the 9.2 release. 
  Regards,

Chuck T 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: IGxDialog 
Author cyril cherian 
Date Aug 23, 2005 
Message Chuck
You are right, we need only ArcEngine runtime to run ArcEngine application. But ArcEngine cannot support all libraries available in ArcGIS. This code use IGxDialog which is in CatalogUI. If you see the OMD, you can see that this is not supported by ArcEngine. I tested the above code on a machine that has both ArcEngine and ArcGIS installed. It works fine. Then I tested it on a machine that has just ArcEngine runtime on it. It never showed up.
Thanks
Cyril

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: IGxDialog 
Author Charles Tilly 
Date Aug 23, 2005 
Message Cyril,

This is good to know. I wasn't aware of this, but it makes sense. Or rather, I believe that ESRI would pull something like this. Thanks for the update. 
  Regards,

Chuck T 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: IGxDialog 
Author Valeria Andronaco 
Date Dec 23, 2009 
Message Hi Chuck,
Your code is perfect.
I would like create a command that automatically add a layer in the TOC. I have tried to change your code but I can not set the DataSource of the layer.
The code changed (attached) add the layer in the TOC but without the data source (with the red exclamation point).

Can you help me please?

Thanks a lot and... Merry Christmas!!!
Valeria

 
 
public override void OnClick()
        {
            //ESRI.ArcGIS.Carto.IActiveView activeView;
            IActiveView pActiveView = (IActiveView)m_hookHelper.FocusMap;
            //activeView = GetActiveViewFromArcMap(m_application);
            ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory GDBFactory = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory();
            IWorkspace pFactory = (IWorkspace)GDBFactory.OpenFromFile(Properties.Settings.Default.DbPath, 0);
            IFeatureWorkspace pWorkspace = (IFeatureWorkspace)pFactory;

            IFeatureLayer pFLayer;
            ILayer pLayer;
            pFLayer = new FeatureLayerClass();
            pFLayer.Name = "Mezzi_Pubblicitari";
            pFLayer.DataSourceType = "Personal Geodatabase Feature Class";
            

            pLayer = pFLayer;
           
            m_hookHelper.ActiveView.FocusMap.AddLayer(pLayer);
m_hookHelper.ActiveView.Refresh();
            
        }