nmfadhil

Using Application.hwnd (ArcGIS 10 & VB.NET Express 2008)

Discussion created by nmfadhil on Feb 10, 2011
Latest reply on Feb 15, 2011 by kenbuja
Hi,

I'm trying to build ArcMap Add-Ins by using ArcGIS 10 and MS VB.NET Express 2008.

How to use or replace application.hwnd as shown in code below?

Sub SaveFirstLayerAsShapefile()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = My.ArcMap.Document
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pMxDoc.FocusMap.Layer(0)
    SaveShapeFileDialog pFeatureLayer.FeatureClass, Application.hwnd
End Sub

Public Function SaveShapeFileDialog(ByRef pFeatureClass As IFeatureClass, Optional lParentWindow As Long = 0)

  On Error GoTo SaveShapefileDialog_ERR

    Dim pGxBrowser As IGxDialog
    Set pGxBrowser = New GxDialog
    
    Dim pFilter As IGxObjectFilter
    Set pFilter = New GxFilterShapefiles
    
    Set pGxBrowser.ObjectFilter = pFilter
    Dim sShapefile As String
    Dim sDir As String
    Dim pGxObject As IGxObject
    
    If Not pGxBrowser.DoModalSave(lParentWindow) Then Exit Function
    
    sShapefile = pGxBrowser.name
    sDir = pGxBrowser.FinalLocation.FullName
    If Right(sDir, 1) <> "\" Then sDir = sDir & "\"
    
    Dim pWorkspaceName As IWorkspaceName
    Set pWorkspaceName = New WorkspaceName
    With pWorkspaceName
        .PathName = sDir
        .WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1"
    End With
    
    Dim pOutDatasetName As IDatasetName
    Set pOutDatasetName = New FeatureClassName
    Set pOutDatasetName.WorkspaceName = pWorkspaceName
    pOutDatasetName.name = sShapefile
    
    'Delete the shapefile, if existing
    Dim pOutName As IName
    Set pOutName = pOutDatasetName
    Dim pOutDataset As IDataset
    On Error Resume Next
    Set pOutDataset = pOutName.Open
    If Not pOutDataset Is Nothing Then
      pOutDataset.Delete
    End If
    Set pOutDataset = Nothing

    Dim pInDataset As IDataset
    Set pInDataset = pFeatureClass
        
    Dim pExportOp As IExportOperation
    Set pExportOp = New ExportOperation
    pExportOp.ExportFeatureClass pInDataset.FullName, _
                                 Nothing, _
                                 Nothing, _
                                 pFeatureClass.Fields.Field(pFeatureClass.Fields.FindField(pFeatureClass.ShapeFieldName)).GeometryDef, _
                                 pOutDatasetName, _
                                 Application.hwnd

  Exit Function

SaveShapefileDialog_ERR:
    Debug.Print "SaveShapefileDialog_ERR: " & Err.Description
    Debug.Assert 0
End Function

Outcomes