用MapControl编程时,如何如何保存当前的MapControl中打开的文档(.mxd)?

eHuaTian 2004-11-19 08:49:05
有一个示例,如下:

'将当前地图保存
Public Function SaveMxFile(ByRef m_pMapDocument As IMapDocument) As Boolean
If m_pMapDocument.IsReadOnly(m_pMapDocument.DocumentFilename) = True

Then
MsgBox("文件只读,不能保存!", , "保存失败")
SaveMxFile = False
Exit Function
End If
On Error Resume Next
m_pMapDocument.Save()
SaveMxFile = True
End Function

但在MapControl中,我不能得到IMapDocument,如何进行?即如何才能得到IMxDocument或

者Application呢,请各位指正,多谢多谢,急急!
...全文
294 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
letheanwater 2004-11-20
  • 打赏
  • 举报
回复
最重要的就是m_pMapDocument.Save m_pMapDocument.UsesRelativePaths这一句

你可以在VB中引入8。3的mapcontrol来看看类似的SAVE的方法需要的参数。:)
对应的修改一下,应该就可以的吧。
eHuaTian 2004-11-19
  • 打赏
  • 举报
回复
Satan0629朋友,你使用的是ArcGIS9吗?我用的是ArcGIS8.3,怎么办呢?多谢多谢
Satan0629 2004-11-19
  • 打赏
  • 举报
回复
Option Explicit

Private m_pAoInitialize As IAoInitialize
Private m_pMapDocument As IMapDocument

Private Sub cmdOpen_Click()

'Open a file dialog for opening map documents
CommonDialog1.DialogTitle = "Open Map Document"
CommonDialog1.Filter = "Map Documents (*.mxd)|*.mxd"
CommonDialog1.ShowOpen

'Exit if no map document is selected
Dim sFilePath As String
sFilePath = CommonDialog1.FileName
If sFilePath = "" Then Exit Sub

'Open document
OpenDocument (sFilePath)

If cmdSave.Enabled = False Then cmdSave.Enabled = True
If cmdSaveAs.Enabled = False Then cmdSaveAs.Enabled = True

End Sub

Private Sub cmdSave_Click()

'Save changes to the current document
SaveDocument

End Sub

Private Sub cmdSaveAs_Click()

'Open a file dialog for saving map documents
CommonDialog1.DialogTitle = "Save Map Document As"
CommonDialog1.Filter = "Map Documents (*.mxd)|*.mxd"
CommonDialog1.ShowSave

'Exit if no map document is selected
Dim sFilePath As String
sFilePath = CommonDialog1.FileName
If sFilePath = "" Then Exit Sub

If sFilePath = m_pMapDocument.DocumentFilename Then
'Save changes to the current document
SaveDocument
Else
'SaveAs a new document with relative paths
m_pMapDocument.SaveAs sFilePath, True
'Open document
OpenDocument (sFilePath)
MsgBox "Document saved successfully!", , "Saved Document"
End If

End Sub

Private Sub Form_Load()

'Create a new AoInitialize object
Set m_pAoInitialize = New AoInitialize
If m_pAoInitialize Is Nothing Then
MsgBox "Unable to initialize. This application cannot run!"
Unload Form1
Exit Sub
End If
'Determine if the product is available
If m_pAoInitialize.IsProductCodeAvailable(esriLicenseProductCodeEngine) = esriLicenseAvailable Then
If m_pAoInitialize.Initialize(esriLicenseProductCodeEngine) <> esriLicenseCheckedOut Then
MsgBox "The initialization failed. This application cannot run!"
Unload Form1
Exit Sub
End If
Else
MsgBox "The ArcGIS Engine product is unavailable. This application cannot run!"
Unload Form1
Exit Sub
End If

'Add toolbar definitions to the ToolbarControl
ToolbarControl1.AddToolbarDef "esriControlCommands.ControlsPageLayoutToolbar", -1, False, 0, esriCommandStyleIconOnly
ToolbarControl1.AddToolbarDef "esriControlCommands.ControlsGraphicElementToolbar", -1, True, 0, esriCommandStyleIconOnly

'Set buddy control
ToolbarControl1.SetBuddyControl PageLayoutControl1
TOCControl1.SetBuddyControl PageLayoutControl1

cmdSave.Enabled = False
cmdSaveAs.Enabled = False

End Sub

Private Sub Form_Unload(Cancel As Integer)

'Shut down the AoInitilaize object
m_pAoInitialize.Shutdown

End Sub

Public Sub OpenDocument(sFilePath As String)

'Create a new map document
Set m_pMapDocument = New MapDocument
'Open the map document selected
m_pMapDocument.Open sFilePath
'Set the PageLayoutControl page layout to the map document page layout
Set PageLayoutControl1.PageLayout = m_pMapDocument.PageLayout
txtMapDocument.Text = m_pMapDocument.DocumentFilename

End Sub

Public Sub SaveDocument()

'Check that the document is not read only
If m_pMapDocument.IsReadOnly(m_pMapDocument.DocumentFilename) = True Then
MsgBox "This map document is read only!", , "Save Failed"
Exit Sub
End If
'Save with the current relative path setting
m_pMapDocument.Save m_pMapDocument.UsesRelativePaths
MsgBox "Changes saved successfully!", , "Saved Document"

End Sub

2,158

社区成员

发帖
与我相关
我的任务
社区描述
它是一种特定的十分重要的空间信息系统。它是在计算机硬、软件系统支持下,对整个或部分地球表层(包括大气层)空间中的有关地理分布数据进行采集、储存、管理、运算、分析、显示和描述的技术系统。
社区管理员
  • 地理信息系统
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧