📄 savemapdocument.frm
字号:
VERSION 5.00
Object = "{BA01FAC9-2AB7-4CC9-9732-938340408ACE}#1.0#0"; "PageLayoutControl.ocx"
Object = "{B7D43581-3CBC-11D6-AA09-00104BB6FC1C}#1.0#0"; "ToolbarControl.ocx"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{370A8DDA-7915-42DC-B4A1-77662C82B046}#1.0#0"; "TOCControl.ocx"
Begin VB.Form Form1
Caption = "Save Map Document"
ClientHeight = 7545
ClientLeft = 60
ClientTop = 345
ClientWidth = 9930
LinkTopic = "Form1"
ScaleHeight = 7545
ScaleWidth = 9930
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtMapDocument
Enabled = 0 'False
Height = 285
Left = 120
TabIndex = 6
Top = 7080
Width = 7695
End
Begin esriTOCControl.TOCControl TOCControl1
Height = 6375
Left = 120
OleObjectBlob = "SaveMapDocument.frx":0000
TabIndex = 5
Top = 600
Width = 2415
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 9120
Top = 2640
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton cmdOpen
Caption = "Open Document..."
Height = 495
Left = 8040
TabIndex = 4
Top = 720
Width = 1815
End
Begin VB.CommandButton cmdSave
Caption = "Save Document"
Height = 495
Left = 8040
TabIndex = 3
Top = 1920
Width = 1815
End
Begin VB.CommandButton cmdSaveAs
Caption = "Save Document As..."
Height = 495
Left = 8040
TabIndex = 2
Top = 1320
Width = 1815
End
Begin esriToolbarControl.ToolbarControl ToolbarControl1
Height = 390
Left = 120
OleObjectBlob = "SaveMapDocument.frx":005D
TabIndex = 1
Top = 120
Width = 9615
End
Begin esriPageLayoutControl.PageLayoutControl PageLayoutControl1
Height = 6375
Left = 2520
OleObjectBlob = "SaveMapDocument.frx":00D1
TabIndex = 0
Top = 600
Width = 5295
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Copyright 1995-2004 ESRI
' All rights reserved under the copyright laws of the United States.
' You may freely redistribute and use this sample code, with or without modification.
' Disclaimer: THE SAMPLE CODE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
' WARRANTIES, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
' FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESRI OR
' CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
' OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
' SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
' INTERRUPTION) SUSTAINED BY YOU OR A THIRD PARTY, HOWEVER CAUSED AND ON ANY
' THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY
' WAY OUT OF THE USE OF THIS SAMPLE CODE, EVEN IF ADVISED OF THE POSSIBILITY OF
' SUCH DAMAGE.
' For additional information contact: Environmental Systems Research Institute, Inc.
' Attn: Contracts Dept.
' 380 New York Street
' Redlands, California, U.S.A. 92373
' Email: contracts@esri.com
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()
'Initialize the application
If CheckOutLicenses(esriLicenseProductCodeEngine) <> esriLicenseCheckedOut Then
If CheckOutLicenses(esriLicenseProductCodeArcView) <> esriLicenseCheckedOut Then
If CheckOutLicenses(esriLicenseProductCodeArcEditor) <> esriLicenseCheckedOut Then
If CheckOutLicenses(esriLicenseProductCodeArcInfo) <> esriLicenseCheckedOut Then
MsgBox "The initialization failed. This application cannot run!"
Unload Form1
Exit Sub
End If
End If
End If
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
Private Function CheckOutLicenses(productCode As esriLicenseProductCode) As esriLicenseStatus
Dim licenseStatus As esriLicenseStatus
licenseStatus = esriLicenseUnavailable
Set m_pAoInitialize = New AoInitialize
If m_pAoInitialize Is Nothing Then CheckOutLicenses = licenseStatus
'Determine if the product is available
licenseStatus = m_pAoInitialize.IsProductCodeAvailable(productCode)
If (licenseStatus = esriLicenseAvailable) Then
licenseStatus = m_pAoInitialize.Initialize(productCode)
End If
CheckOutLicenses = licenseStatus
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -