阅读:1601回复:5
文档保存问题
<P>如何用mapcontrol+vb实现对mxd文档的保存</P><img src="images/post/smile/dvbbs/em02.gif" />
|
|
1楼#
发布于:2004-12-30 19:44
<P>你可以在帮助里查找saveas,仔细看看里面的属性和方法</P><P>Option Explicit</P><P>Private m_pAoInitialize As IAoInitialize
Private m_pMapDocument As IMapDocument</P><P>Private Sub cmdOpen_Click()</P><P> '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</P><P>Private Sub cmdSave_Click() 'Save changes to the current document SaveDocument</P><P>End Sub</P><P>Private Sub cmdSaveAs_Click()</P><P> 'Open a file dialog for saving map documents CommonDialog1.DialogTitle = "Save Map Document As" CommonDialog1.Filter = "Map Documents (*.mxd)|*.mxd" CommonDialog1.ShowSave</P><P> '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</P><P>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</P><P>End Sub</P><P>Private Sub Form_Unload(Cancel As Integer)</P><P> 'Shut down the AoInitilaize object m_pAoInitialize.Shutdown</P><P>End Sub</P><P>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</P><P>End Sub</P><P>Public Sub SaveDocument()</P><P> '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"</P><P>End Sub</P> |
|
|
2楼#
发布于:2004-12-30 22:00
谢谢斑竹,但是好象8.3中没有IMapDocument类,这应该是9.0的代码吧?仍然感谢您!!!!!!!!!!!
|
|
3楼#
发布于:2004-12-31 10:46
<P>可以保存为其他自定义格式的</P>
<P>Dim pPersistStream As esriCore.IPersistStream Dim pMemoryBlobStream As esriCore.IMemoryBlobStream</P> <P>Set pPersistStream = pMapControl.Map Set pMemoryBlobStream = New esriCore.MemoryBlobStream pPersistStream.Save pMemoryBlobStream, 0 pMemoryBlobStream.SaveToFile "c:\temp.map" </P> [此贴子已经被作者于2004-12-31 10:48:19编辑过]
|
|
|
4楼#
发布于:2004-12-31 10:47
Dim pMemoryBlobStream As esriCore.IMemoryBlobStream
Dim pPersistStream As esriCore.IPersistStream Set pPersistStream = pMapControl.Map Set pMemoryBlobStream = New esriCore.MemoryBlobStream pMemoryBlobStream.LoadFromFile "c:\test.map" pPersistStream.Load pMemoryBlobStream |
|
|
5楼#
发布于:2005-01-05 12:39
谢谢 您的帮助
|
|