100楼#
发布于:2005-07-26 11:01
如何在ArcMap中加入Text和dBASE文件
<P>l 要点</P> <P 17.95pt">首先为Text文件或dBASE文件创建一个与之对应的ITable接口对象,然后通过IMap实例获得IStandaloneTable接口对象和IStandaloneTableCollection接口对象,并设置其属性,最后使用IStandaloneTableCollection.AddStandaloneTable方法将Text文件或dBASE文件加入到当前的ArcMap中。加入Text文件或dBASE文件的区别仅在于创建ITable对象时IWorkspaceFactory的类型不同,加入Text文件时是TextFileWorkspaceFactory类型,加入dBASE文件时是ShapefileWorkspaceFactory类型。</P> <P 17.95pt">主要用到了IWorkspaceFactory接口,IWorkspace接口,IFeatureWorkspace接口,ITable接口,IStandaloneTable接口和IStandaloneTableCollection接口。</P> <P 39pt; TEXT-INDENT: -42pt"> l 程序说明</P> <P 17.95pt">函数AddTextFile通过文件路径sFilePath和文件名sFileName找到Text文件并为其创建ITable对象</P> <P 17.95pt">函数AddDBASEFile通过文件路径sFilePath和文件名sFileName找到dBASE文件并为其创建ITable对象</P> <P 17.95pt">函数Add_Table_TOC将ITable对象pTable加入到当前的ArcMap中。</P> <P 39pt; TEXT-INDENT: -42pt"> l 代码</P> <P> <TABLE height=43 width=541 align=center border=0><!--DWLayoutTable--> <TR> <TD vAlign=top width=535 height=75> <P 10pt">Private Sub AddTextFile(ByVal sFilePath As String, ByVal sFileName As String)</P> <P 10pt"> Dim pWorkspaceFactory As IWorkspaceFactory<BR> Dim pWorkspace As IWorkspace<BR> Dim pFeatureWorkspace As IFeatureWorkspace<BR> Dim pTable As ITable<BR> Dim sDir As String </P> <P 10pt">On Error GoTo ErrorHandler:</P> <P 10pt"> sDir = Dir(sFilePath ; sFileName ; ".txt")<BR> If (sDir = "") Then<BR> MsgBox (sFileName ; ".txt" ; " 文件不存在")<BR> Exit Sub<BR> End If</P> <P 10pt"> 'Get the ITable from the geodatabase<BR> Set pWorkspaceFactory = New TextFileWorkspaceFactory<BR> Set pWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0)<BR> Set pFeatureWorkspace = pWorkspace<BR> Set pTable = pFeatureWorkspace.OpenTable(sFileName ; ".txt")</P> <P 10pt"> 'Add the table<BR> Add_Table_TOC pTable</P> <P 10pt"> Exit Sub</P> <P 10pt">ErrorHandler:<BR> MsgBox Err.Description</P> <P 10pt">End Sub</P> <P 10pt">Private Sub AddDBASEFile(ByVal sFilePath As String, ByVal sFileName As String)</P> <P 10pt"> Dim pWorkspaceFactory As IWorkspaceFactory<BR> Dim pWorkspace As IWorkspace<BR> Dim pFeatureWorkspace As IFeatureWorkspace<BR> Dim pTable As ITable</P> <P 10pt">On Error GoTo ErrorHandler:</P> <P 10pt"> 'Get the ITable from the geodatabase<BR> Set pWorkspaceFactory = New ShapefileWorkspaceFactory<BR> Set pWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0)<BR> Set pFeatureWorkspace = pWorkspace<BR> Set pTable = pFeatureWorkspace.OpenTable(sFileName)</P> <P 10pt"> 'Add the table<BR> Add_Table_TOC pTable</P> <P 10pt"> Exit Sub</P> <P 10pt">ErrorHandler:<BR> MsgBox Err.Description</P> <P 10pt">End Sub</P> <P 10pt">Private Sub Add_Table_TOC(pTable As ITable)</P> <P 10pt"> Dim pDoc As IMxDocument<BR> Dim pMap As IMap<BR> Dim pStandaloneTable As IStandaloneTable<BR> Dim pStandaloneTableC As IStandaloneTableCollection</P> <P 10pt">On Error GoTo ErrorHandler:</P> <P 10pt"> Set pDoc = ThisDocument<BR> Set pMap = pDoc.FocusMap</P> <P 10pt"> 'Create a new standalone table and add it<BR> 'to the collection of the focus map<BR> Set pStandaloneTable = New StandaloneTable<BR> Set pStandaloneTable.Table = pTable<BR> Set pStandaloneTableC = pMap<BR> pStandaloneTableC.AddStandaloneTable pStandaloneTable</P> <P 10pt"> 'Refresh the TOC<BR> pDoc.UpdateContents</P> <P 10pt"> Exit Sub</P> <P 10pt">ErrorHandler:<BR> MsgBox Err.Description</P> <P 10pt">End Sub</P> <P 10pt">Private Sub UIButtonControl1_Click()</P> <P 10pt"> Dim pVBProject As VBProject</P> <P 10pt">On Error GoTo ErrorHandler:</P> <P 10pt"> Set pVBProject = ThisDocument.VBProject</P> <P 10pt"> 'Add text file to ArcMap. Dont include .txt extension<BR> AddTextFile pVBProject.FileName ; "\..\..\..\.." ; "\data\", "Continents"</P> <P 10pt"> 'Add dBASE file to ArcMap<BR> AddDBASEFile pVBProject.FileName ; "\..\..\..\.." ; "\data\", "Continents"</P> <P 10pt"> Exit Sub</P> <P 10pt">ErrorHandler:<BR> MsgBox Err.Description</P> <P 10pt">End Sub</P></TD></TR></TABLE></P> |
|
|
101楼#
发布于:2005-07-26 11:00
如何加载Shape文件
<br><FONT size=2>本例实现的是在ArcMap中连接指定的Shape文件,并将其加载到当前激活的Map中。<FONT face="MS UI Gothic"> </FONT></FONT> <P 39pt; TEXT-INDENT: -42pt"> l 要点</P> <P 21pt; LINE-HEIGHT: 14pt">通过FeatureLayer类实现IFeatureLayer接口对象,设置IFeatureLayer.FeatureClass属性和Name属性,使用IMap.AddLayer方法将新层添加到当前地图。利用IWorkspaceFacktory接口、IFeatureWorkspace接口和IFeatureLayer接口实现连接Shape文件</P> <P 39pt; TEXT-INDENT: -42pt"> l 程序说明</P> <P 17.95pt">函数OpenShapeFile根据输入的Shape文件路径sFilePath,将文件名为sFileName的Shape文件连接到当前激活的Map中去。</P> <P 39pt; TEXT-INDENT: -42pt"> l 代码</P> <TABLE height=43 width=541 align=center border=0><!--DWLayoutTable--> <TR> <TD vAlign=top width=535 height=75> <P 10pt">Private Sub OpenShapeFile(ByVal sFilePath As String, ByVal sFileName As String)</P> <P 10pt"> Dim pWorkspaceFactory As IWorkspaceFactory<BR> Dim pFeatureWorkspace As IFeatureWorkspace<BR> Dim pFeatureLayer As IFeatureLayer<BR> Dim pMxDocument As IMxDocument<BR> Dim pMap As IMap<BR> Dim sDir As String </P> <P 10pt">On Error GoTo ErrorHandler:</P> <P 10pt"> sDir = Dir(sFilePath ; "\" ; sFileName ; ".shp")<BR> If (sDir = "") Then<BR> sDir = Dir(sFilePath ; "\" ; sFileName)<BR> If (sDir = "") Then<BR> MsgBox ("文件不存在")<BR> Exit Sub<BR> End If<BR> End If</P> <P 10pt"> 'Create a new ShapefileWorkspaceFactory object and open a shapefile folder<BR> Set pWorkspaceFactory = New ShapefileWorkspaceFactory<BR> Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0)<BR><BR> 'Create a new FeatureLayer and assign a shapefile to it<BR> Set pFeatureLayer = New FeatureLayer<BR> Set pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(sFileName)<BR> pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName</P> <P 10pt"> 'Add the FeatureLayer to the focus map<BR> Set pMxDocument = Application.Document<BR> Set pMap = pMxDocument.FocusMap<BR> pMap.AddLayer pFeatureLayer</P> <P 10pt"> Exit Sub</P> <P 10pt">ErrorHandler:<BR> MsgBox Err.Description</P> <P 10pt">End Sub</P> <P 10pt">Private Sub UIButtonControl1_Click()</P> <P 10pt"> Dim pVBProject As VBProject</P> <P 10pt">On Error GoTo ErrorHandler:</P> <P 10pt"> Set pVBProject = ThisDocument.VBProject<BR> OpenShapeFile pVBProject.FileName ; "\..\..\..\.." ; "\data\", "Continents"</P> <P 10pt"> Exit Sub</P> <P 10pt">ErrorHandler:<BR> MsgBox Err.Description</P> <P 10pt">End Sub</P></TD></TR></TABLE> |
|
|
102楼#
发布于:2005-07-26 10:59
<P>如何创建放大镜(虫眼)</P>
<P> </P> <P 17.95pt">本例要实现的是如何创建放大镜(虫眼),将所选区域放大一定的倍数。</P> <P 39pt; TEXT-INDENT: -39pt">l 要点</P> <P 17.95pt">用户通过定义IMapInset、IMapInsetWindow、IDataWindowFactory三个接口,运用它们的方法、属性来创建放大镜(虫眼)。</P> <P 39pt; TEXT-INDENT: -39pt">l 程序说明</P> <P 17.95pt">运用这个子程序生成了一个新的放大镜窗口,在本例中将放大率设定为200%代替原来的400%。</P> <P 39pt; TEXT-INDENT: -39pt">l 代码</P> <P> <TABLE height=43 width=541 align=center border=0> <TR> <TD width=531> <P>Public Sub CreateMagnifierWindow()<BR><BR> Dim pMapInset As IMapInset<BR> Dim pMapInsetWindow As IMapInsetWindow<BR> Dim pDataWindowFactory As IDataWindowFactory<BR><BR> Set pDataWindowFactory = New MapInsetWindowFactory<BR> If pDataWindowFactory.CanCreate(Application) Then<BR> Set pMapInsetWindow = pDataWindowFactory.Create(Application)<BR> Set pMapInset = pMapInsetWindow.MapInset<BR> 'Set the zoom percent to 200%<BR> pMapInset.ZoomPercent = 200<BR> pMapInsetWindow.Show True<BR> End If<BR><BR>End Sub</P></TD></TR></TABLE></P> |
|
|
103楼#
发布于:2005-07-26 10:58
<P>如何调用ArcMap中现有的功能</P>
<P 17.95pt">如何调用ArcMap中现有的功能,比如菜单栏、工具栏中的某些功能。这些都可以通过UID来实现。本例是通过UID调用“另存为”功能。</P> <P>可以通过两种方法得到UID:</P> <P>方法一:运用ArcID模块</P> <P 39pt; TEXT-INDENT: -39pt">l 要点</P> <P 17.95pt">通过ArcID获得UID,ArcID是ArcMap的VBA中的模块。只需要知道要调用功能的名称运用代码就可以实现。</P> <P 39pt; TEXT-INDENT: -39pt">l 程序说明</P> <P 17.95pt">程序通过运用ArcID模块和命令名称来实现调用“另存为”的功能。</P> <P 39pt; TEXT-INDENT: -39pt">l 代码</P> <P>Sub ExecuteCmd()<BR> Dim pCommandItem As ICommandItem<BR> ' Use ArcID module and the Name of the SaveAs command<BR> Set pCommandItem = Application.Document.CommandBars.Find(arcid.File_SaveAs)<BR> pCommandItem.Execute<BR>End Sub</P> <P>方法二:直接写代码</P> <P 39pt; TEXT-INDENT: -39pt">l 要点</P> <P 17.95pt">通过直接写代码获得UID实现调用功能。</P> <P 39pt; TEXT-INDENT: -39pt">l 程序说明</P> <P 17.95pt">写入文件菜单项的GUID(CLSID或ProgID)来调用文件菜单项,同时还需要通过设置Subtype的值来调用文件菜单项的“另存为”功能。</P> <P 39pt; TEXT-INDENT: -39pt">l 代码</P> <P> <TABLE height=43 width=541 align=center border=0> <TR> <TD width=531> <P>Sub ExecuteCmd2()<BR> Dim pUID As New UID<BR> Dim pCommandItem As ICommandItem<BR> ' Use the GUID of the Save command<BR> pUID.Value = "{119591DB-0255-11D2-8D20-080009EE4E51}"<BR> ' or you can use the ProgID<BR> ' pUID.Value = "esriCore.MxFileMenuItem"<BR> pUID.SubType = 3<BR> Set pCommandItem = Application.Document.CommandBars.Find(pUID)<BR> pCommandItem.Execute<BR>End Sub</P></TD></TR></TABLE></P> |
|
|
104楼#
发布于:2005-07-26 10:58
<P>如何使用ArcGIS的对话框</P>
<P 17.95pt">添加对话框可以通过相应的接口实现。比如“添加数据对话框”使用IaddDataDialog接口,“生成点坐标对话框” 使用ICoordinateDialog接口,“生成字符串对话框”使用IGetStringDialog接口,“生成数值对话框”使用INumberDialog接口等等。本例以添加数据对话框(Add Data Dialog)为例,讲述对话框是如何通过接口实现添加的。</P> <P 39pt; TEXT-INDENT: -42pt">l 要点</P> <P 17.95pt">用户通过实现IaddDataDialog接口来创建定制的添加数据对话框,IaddDataDialog接口包括Document和Map属性和Show事件。</P> <P 39pt; TEXT-INDENT: -42pt">l 程序说明</P> <P -0.2pt; TEXT-INDENT: 18.2pt">在程序中除了必须生成IaddDataDialog接口的实例外,还必须指定对话框的Document和Map。当为AddDataDialog指定Document和Map之后,系统会自动将用户选择的数据加入到指定Document和Map中。最后实现在ArcMap中添加数据的对话框。</P> <P 39pt; TEXT-INDENT: -39pt">l 代码</P> <P> <TABLE height=43 width=541 align=center border=0> <TR> <TD width=531> <P>Sub ShowProgress()<BR> Dim mDocument As IMxDocument<BR> Dim mAddDataDialog As IAddDataDialog<BR> Set mAddDataDialog = New AddDataDialog<BR> Set mDocument = ThisDocument<BR> mAddDataDialog.Document = mDocument<BR> mAddDataDialog.Map = mDocument.FocusMap<BR> mAddDataDialog.Show Application.hWnd, True<BR>End Sub</P></TD></TR></TABLE></P> |
|
|
105楼#
发布于:2005-07-26 10:57
<P>如何使用状态条(StatusBar)与进度条(ProgressBar)</P>
<P 17.95pt">本例要演示的是如何使用状态条(StatusBar)与进度条(ProgressBar)。实现后的结果为在ArcMap中,状态条位于其底部,它显示ArcMAP当前状态的信息,包含进度条。</P> <P 39pt; TEXT-INDENT: -42pt">l 要点</P> <P 17.95pt">一般情况下,通过ArcMAP的Application实例获取IstatusBar的实例,然后再通过StatusBar获取IprogressBar的实例,并将IprogressBar的实例赋给IstepProgressor类型的变量。</P> <P 39pt; TEXT-INDENT: -42pt">l 程序说明</P> <P 17.95pt">运行函数ShowProgress将在ArcMap的下方添加一个状态条(StatusBar)和进度条(ProgressBar)。</P> <P 39pt; TEXT-INDENT: -42pt">l 代码</P> <P> <TABLE height=43 width=541 align=center border=0> <TR> <TD width=531> <P>Sub ShowProgress()<BR> On Error GoTo err1<BR> Dim pDocument As IMxDocument<BR> Dim pMap As IMap<BR> Dim pLayer As ILayer<BR> Dim pFeatureLayer As IFeatureLayer<BR> Dim pFeatureCursor As IFeatureCursor<BR> Dim pFeatureClass As IFeatureClass<BR> Dim pFeature As IFeature<BR> Dim dSum As Double<BR> Dim lFieldIndex As Long<BR> Dim lNumFeat As Long<BR> Dim dInterval As Double<BR> Set pDocument = Application.Document<BR> Set pMap = pDocument.FocusMap<BR> Set pLayer = pMap.Layer(0)<BR> Set pFeatureLayer = pLayer<BR> Set pFeatureClass = pFeatureLayer.FeatureClass<BR> Set pFeatureCursor = pFeatureLayer.Search(Nothing, True)<BR> Dim pStatusBar As IStatusBar<BR> Set pStatusBar = Application.StatusBar<BR> Dim pStepProgressor As IStepProgressor<BR> Set pStepProgressor= pStatusBar.ProgressBar<BR> lNumFeat = pFeatureClass.FeatureCount(Nothing)<BR> dInterval = lNumFeat / 100<BR> Set pFeature = pFeatureCursor.NextFeature<BR> ' 字段名"FID"用户根据实际而改变<BR> lFieldIndex = pFeature.Fields.FindField("FID")<BR> Dim PauseTime, Start, Finish, TotalTime, i<BR> PauseTime = 0.5<BR> pStepProgressor.MinRange = 1<BR> pStepProgressor.MaxRange = lNumFeat<BR> pStepProgressor.StepValue = dInterval<BR> For i = 1 To lNumFeat<BR> dSum = dSum + pFeature.Value(lFieldIndex)<BR> Set pFeature = Nothing<BR> Set pFeature = pFeatureCursor.NextFeature<BR> pStepProgressor.Position = i<BR> pStepProgressor.Message = "Reading record " ; Str(i) ; ". Sum =" ; Str(dSum)<BR> pStepProgressor.Step<BR> pStepProgressor.Show<BR> Start = Timer<BR> Do While Timer < Start + PauseTime<BR> DoEvents<BR> Loop<BR> Next<BR> pStepProgressor.Hide<BR> Exit Sub<BR> err1:<BR> MsgBox Err.Description<BR>End Sub</P></TD></TR></TABLE></P> |
|
|
106楼#
发布于:2005-07-26 10:56
<P>本例要实现的是如何创建、使用定制的Extension</P>
<P> 要点</P> <P 17.95pt">用户需要实现IExtension接口来创建定制的Extension。IExtension接口包括Name属性和startup和shutdown事件。</P> <P 17.95pt">·创建并注册Extension的步骤:</P> <P 17.95pt">1.实现IExtension接口;</P> <P 17.95pt">2.编译成DLL;</P> <P 17.95pt">3.调用windows目录下system32子目录下的regsvr32.exe用下面的形式注册编译好的DLL</P> <P 17.95pt">win目录\system32\regsvr32.exe <路径>\<文件名>.dll</P> <P 17.95pt">4.运行<arcmap目录>\arcexe81\Bin\categories.exe,在打开的Component Catregory Manager中找到ESRI Mx Extensions,点击Add Object…按钮将上面注册的DLL文件加入,并选中实现IExtension接口的类名即可。</P> <P 0cm; TEXT-INDENT: 0cm">l 程序说明</P> <P 17.95pt">用户通过在类模块中实现IExtension接口来创建定制的Extension。Extension将在ArcMap打开时自动加载,在ArcMap关闭时自动卸载。</P> <P 21pt; TEXT-INDENT: -21pt">l 代码</P> <P> <TABLE height=43 width=541 align=center border=0> <TR> <TD width=531> <P>Option Explicit<BR> Implements IExtension<BR> Dim m_pApplication As IApplication<BR> ' Need to listen for the MxDocument events<BR> Dim WithEvents m_pDocument As MxDocument </P> <P> Private Property Get IExtension_Name() As String<BR> IExtension_Name = "My Extension"<BR> End Property </P> <P> Private Sub IExtension_Shutdown()<BR> ' Clear the reference to the Application and MxDocument<BR> Set m_pApplication = Nothing<BR> Set m_pDocument = Nothing<BR> End Sub </P> <P>Private Sub IExtension_Startup(initializationData As Variant)<BR> ' This extension is an ArcMap Extension. When this extension in loaded on<BR> ' ArcMap startup, initializationData is passed in as a reference to the<BR> ' Application object<BR> Set m_pApplication = initializationData<BR> 'Start listening for the MxDocument events.<BR> Set m_pDocument = m_pApp.Document<BR> End Sub </P> <P> Private Function m_pDocument_NewDocument() As Boolean<BR> ' Do something when a new document is created<BR> MsgBox "Creating a new document."<BR> End Function </P> <P> Private Function m_pDocument_OpenDocument() As Boolean<BR> ' So something when a document is opened.<BR> MsgBox "Opening a document"<BR> End Function</P></TD></TR></TABLE></P> |
|
|
107楼#
发布于:2005-07-26 10:56
<P>本例要实现的是如何创建定制的可停靠窗口(Dockable Window)</P>
<P 21pt; TEXT-INDENT: -21pt">l 要点</P> <P 17.95pt">用户通过在类模块中实现IDockableWindowDef接口来创建定制的可停靠窗口(Dockable Window)。IDockableWindowDef接口包括Caption、ChildHWND,UserData及Name等属性和OnCreate、OnDestroy事件。</P> <P 17.95pt">·ChildHWND属性表示可停靠窗口包含的Window的Handle。</P> <P 17.95pt">·OnCreate事件的参数hook传入ArcGIS的Application实例。</P> <P 17.95pt">·创建并注册可停靠窗口的步骤:</P> <P -0.1pt; TEXT-INDENT: 18.05pt">1、实现IdockableWindowDef接口(参见实例);</P> <P 17.95pt">2、编译成DLL;</P> <P 17.95pt">3、调用windows目录下system32子目录下的regsvr32.exe用下面的形式注册编译好的DLL:</P> <P 17.95pt">win目录\system32\regsvr32.exe <路径>\<文件名>.dll</P> <P 17.95pt">4、运行<arcmap目录>\arcexe81\Bin\categories.exe,在打开的Component Catregory Manager中找到ESRI Mx Dockable Window,点击Add Object…按钮将上面注册的DLL文件加入,并选中实现IdockableWindowDef接口的类名即可。</P> <P 0cm; TEXT-INDENT: 0cm">l 程序说明</P> <P 17.95pt">类模块 ClsDockableWindow只是创建与注册可停靠窗口,但还不能用,还必须定义一个IdockableWindow接口的变量引用注册的类(必须用IdockableWindowsManager接口的GetDockableWindow获取,其ID号用"实现IdockableWindowDef接口的工程名project1. 实现IdockableWindowDef接口的类名class1")。</P> <P 21pt; TEXT-INDENT: -21pt">l 代码</P> <P> <TABLE height=43 width=541 align=center border=0> <TR> <TD width=531> <P>'类模块 ClsDockableWindow<BR>Option Explicit<BR>Implements IDockableWindowDef<BR>Dim m_pApplication As IApplication </P> <P>Private Property Get IDockableWindowDef_Caption() As String<BR> IDockableWindowDef_Caption = "Dockable Window"<BR>End Property </P> <P>Private Property Get IDockableWindowDef_ChildHWND() As esriCore.OLE_HANDLE<BR> '将FrmDWin窗口的Handle赋给IDockableWindowDef_ChildHWND<BR> IDockableWindowDef_ChildHWND = FrmDWin.hWnd<BR>End Property </P> <P>Private Property Get IDockableWindowDef_Name() As String<BR> IDockableWindowDef_Name = "docwin"<BR>End Property </P> <P>Private Sub IDockableWindowDef_OnCreate(ByVal hook As Object)<BR> Set m_pApplication = hook<BR>End Sub </P> <P>Private Sub IDockableWindowDef_OnDestroy()<BR> Set m_pApplication = Nothing<BR>End Sub </P> <P>Private Property Get IDockableWindowDef_UserData() As Variant<BR>End Property </P> <P>'类模块 class1<BR>Option Explicit<BR>Implements ICommand<BR>Dim m_pApp As IApplication<BR>Dim m_pDWMgr As IDockableWindowManager<BR>Dim m_pDWin As IDockableWindow </P> <P>Private Property Get ICommand_Bitmap() As esriCore.OLE_HANDLE<BR>End Property </P> <P>Private Property Get ICommand_Caption() As String<BR> ICommand_Caption = "Dockable Window"<BR>End Property </P> <P>Private Property Get ICommand_Category() As String<BR> ICommand_Category = "Dockable Window"<BR>End Property </P> <P>Private Property Get ICommand_Checked() As Boolean<BR>End Property </P> <P>Private Property Get ICommand_Enabled() As Boolean<BR> ICommand_Enabled = True<BR>End Property </P> <P>Private Property Get ICommand_HelpContextID() As Long<BR>End Property </P> <P>Private Property Get ICommand_HelpFile() As String<BR>End Property </P> <P>Private Property Get ICommand_Message() As String<BR>End Property </P> <P>Private Property Get ICommand_Name() As String<BR> ICommand_Name = "DocWin"<BR>End Property </P> <P>Private Sub ICommand_OnClick()<BR> m_pDWin.Show Not m_pDWin.IsVisible<BR>End Sub </P> <P>Private Sub ICommand_OnCreate(ByVal hook As Object)<BR> Set m_pApp = hook<BR> ' QI(Dockable Window)<BR> Set m_pDWMgr = hook<BR> Dim pid As New UID<BR> pid.Value = "Prodockablewindow.Clsdockablewindow"<BR> Set m_pDWin = m_pDWMgr.GetDockableWindow(pid)<BR>End Sub </P> <P>Private Property Get ICommand_Tooltip() As String<BR> ICommand_Tooltip = "Dockable Window"<BR>End Property</P></TD></TR></TABLE></P> |
|
|
108楼#
发布于:2005-07-26 10:55
<P>如何创建定制的ToolControl</P>
<P 17.95pt">本例要实现的是如何创建定制的ToolControl。ToolControl是指具有ComboBox的下拉列表 或 EditBox的编辑功能的一类控件。要创建定制的ToolControl,必须在类模块中实现<STRONG>ICommand</STRONG> 和 IToolControl接口。IToolControl接口包括<STRONG>hWnd</STRONG>属性和<STRONG>OnDrop</STRONG>, <STRONG>OnFocus</STRONG>事件。</P> <P 0cm; TEXT-INDENT: 0cm">l 要点</P> <P 17.95pt">·IToolControl接口的<STRONG>hWnd</STRONG>属性,接受一个Window Handle。</P> <P 17.95pt">·IToolControl接口的<STRONG>OnDrop事件,支持</STRONG>ToolControl的拖放,传入参数<I>barType</I>表示Bar类型。</P> <P 17.95pt">·IToolControl接口的<STRONG>OnFocus事件,传入</STRONG>IcompletionNotify类型的<STRONG>参数</STRONG><I>complete</I>,可以通过执行IcompletionNotify接口的SetComplete方法告之ArcMAP,ToolControl可以失去Focus。</P> <P 0cm; TEXT-INDENT: 0cm">l 程序说明</P> <P 21pt">本例中涉及三个模块,详细描述如下,其中,在类模块中实现了IToolBarDef接口来创建自己的ToolControl。</P> <P 21pt; TEXT-INDENT: -21pt">l 代码</P> <P> <TABLE height=43 width=541 align=center border=0> <TR> <TD width=531> <P>'1、frmImageCombo.frm模块,定义选中Combox某一项之后实现的功能。要求在Form上放置一个<BR>'ImageComb控件(名为ImageCombo1)和一个ImageList控件(名为ImageList1),并在ImageList1<BR>'中添加三张图片。</P> <P>Private Sub Form_Load()<BR> ' 设置ImageCombo1的选择Item<BR> Me.ImageCombo1.ImageList = Me.ImageList1<BR> Me.ImageCombo1.ComboItems.Add 1, "Red", "Red"<BR> Me.ImageCombo1.ComboItems.Add 2, "Blue", "Blue"<BR> Me.ImageCombo1.ComboItems.Add 3, "Green", "Green"<BR> Me.ImageCombo1.ComboItems(1).Image = 1<BR> Me.ImageCombo1.ComboItems(2).Image = 2<BR> Me.ImageCombo1.ComboItems(3).Image = 3<BR>End Sub </P> <P>Private Sub ImageCombo1_Click()<BR> ' 选择颜色<BR> Dim sel As Variant<BR> sel = Me.ImageCombo1.SelectedItem<BR> Dim color As Variant<BR> Select Case sel<BR> Case "Blue"<BR> color = vbBlue<BR> Case "Red"<BR> color = vbRed<BR> Case "Green"<BR> color = vbGreen<BR> End Select<BR> Dim pDocument As IMxDocument<BR> Set pDocument = g_pApplication.Document<BR> ' 设置颜色<BR> Dim pRgbColor As IrgbColor<BR> Set pRgbColor = New RgbColor<BR> pRgbColor.RGB = color<BR> ' 改变选中部分的颜色<BR> Dim pSelectionEnvironment As ISelectionEnvironment<BR> Set pSelectionEnvironment = New SelectionEnvironment<BR> Set pSelectionEnvironment.DefaultColor = pRgbColor<BR> ' 刷新视图<BR> pDocument.ActivatedView.Refresh<BR> ' 通知ArcMap,ToolControl现在可以失去Focus<BR> g_pCompletionNotify.SetComplete<BR>End Sub </P> <P>' 2、modPublicVars.bas模块,定义工程中用到的全局变量。<BR>Option Explicit<BR>Public g_pApplication As IApplication<BR>Public g_pCompletionNotify As IcompletionNotify</P> <P>' 3、CustImageCombo.cls模块,实现接口Icommand和IToolControl。<BR>Option Explicit<BR>Implements ICommand<BR>Implements IToolControl </P> <P>Private Property Get ICommand_Bitmap() As esriCore.OLE_HANDLE<BR>End Property </P> <P>Private Property Get ICommand_Caption() As String<BR> ICommand_Caption = "Custom ImageCombo"<BR>End Property </P> <P>Private Property Get ICommand_Category() As String<BR> ICommand_Category = "Developer Samples"<BR>End Property </P> <P>Private Property Get ICommand_Checked() As Boolean<BR>End Property </P> <P>Private Property Get ICommand_Enabled() As Boolean<BR> ICommand_Enabled = True<BR>End Property </P> <P>Private Property Get ICommand_HelpContextID() As Long<BR>End Property </P> <P>Private Property Get ICommand_HelpFile() As String<BR>End Property </P> <P>Private Property Get ICommand_Message() As String<BR> ICommand_Message = "Change feature selection color"<BR>End Property </P> <P>Private Property Get ICommand_Name() As String<BR> ICommand_Name = "DevelperSamples_CustomImageCombo"<BR>End Property </P> <P>Private Sub ICommand_OnClick()<BR>End Sub </P> <P>Private Sub ICommand_OnCreate(ByVal hook As Object)<BR> Set g_pApp = hook<BR>End Sub </P> <P>Private Property Get ICommand_Tooltip() As String<BR> ICommand_Tooltip = "Change Selection Color"<BR>End Property </P> <P>Private Property Get IToolControl_hWnd() As esriCore.OLE_HANDLE<BR> '将frmImageCombo.ImageCombo1的Window Handle赋给IToolControl_hWnd<BR>IToolControl_hWnd = frmImageCombo.ImageCombo1.hWnd<BR>End Property </P> <P 16pt; TEXT-INDENT: -16pt">Private Function IToolControl_OnDrop(ByVal barType As esriCore.esriCmdBarType) As Boolean '仅能将ToolControl拖放到ToolBar上<BR> If barType = esriCmdBarTypeToolbar Then<BR> IToolControl_OnDrop = True<BR> End If</P> <P 16pt; TEXT-INDENT: -16pt">End Function </P> <P>Private Sub IToolControl_OnFocus(ByVal complete As esriCore.ICompletionNotify)<BR> Set g_pCompletionNotify = complete<BR>End Sub</P></TD></TR></TABLE></P> |
|
|
109楼#
发布于:2005-07-26 10:54
<P>本例要实现的是如何创建定制的菜单(Menu)</P>
<P 21pt; TEXT-INDENT: -21pt">l 要点</P> <P 18.1pt">用户通过在类模块中实现IMenuDef接口来创建定制的菜单(Menu),如果要使菜单出现在Customize Dialog的Menus类型中,必须同时实现IrootLevelMenu接口,它表明菜单为root menu。IMenuDef接口包括 Caption、ItemCount及Name三个属性和GetItemInfo方法。类似IToolBarDef(参照1.2.3)</P> <P 21pt; TEXT-INDENT: -21pt">l 程序说明</P> <P 21pt">程序在类模块中实现IMenuDef接口来创建定制的菜单(Menu)。</P> <P 21pt; TEXT-INDENT: -21pt">l 代码</P> <P> <TABLE height=43 width=541 align=center border=0> <TR> <TD width=531> <P>Option Explicit </P> <P> 'Implement the IMenuDef interface and IRootLevelMenu interface<BR> Implements IMenuDef<BR> Implements IRootLevelMenu </P> <P> Private Property Get IMenuDef_Caption() As String<BR> ' Set the string that appears as the menu's title<BR> IMenuDef_Caption = "MyMenu"<BR> End Property </P> <P> Private Sub IMenuDef_GetItemInfo(ByVal pos As Long, _<BR>ByVal itemDef As esriCore.IItemDef)<BR> ' Define the commands that will be on the menu. The built-in ArcMap<BR> ' Full Extent command, and Fixed Zoom In command are added to this custom menu.<BR> ' ID is the ClassID of the command. Group determines whether the command<BR> ' begins a new group on the menu<BR> Select Case pos<BR> Case 0<BR> itemDef.ID = "promenu.clsmultitem"<BR> itemDef.Group = False<BR> Case 1<BR> itemDef.ID = "esriCore.FullExtentCommand"<BR> itemDef.Group = True<BR> Case 2<BR> itemDef.ID = "esriCore.ZoomInFixedCommand"<BR> itemDef.Group = False<BR> End Select<BR> End Sub </P> <P> Private Property Get IMenuDef_ItemCount() As Long<BR> ' Set how many commands will be on the menu<BR> IMenuDef_ItemCount = 3<BR> End Property </P> <P> Private Property Get IMenuDef_Name() As String<BR> ' Set the internal name of the menu.<BR> IMenuDef_Name = "MyMenu"<BR> End Property</P></TD></TR></TABLE></P> |
|
|