⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 savemapdocument.cpp

📁 好不容易找到的用多种语言写的ArcGisEngine二次开发程序
💻 CPP
字号:
#include "SaveMapDocument.h"

// Control Interfaces
IPageLayoutControlPtr g_ipPageLayoutControl;
IToolbarControlPtr g_ipToolbarControl;
ITOCControlPtr g_ipTOCControl;

IMapDocumentPtr g_ipMapDoc;   // the current map document

// Widgets
extern Widget g_currentMapText;

int main(int argc, char* argv[])
{
  // Initialize the Engine
  ::AoInitialize(NULL);
  {
    IAoInitializePtr ipInit(CLSID_AoInitialize);
    if (ipInit == 0)
    {
      std::cerr << "Unable to initialize. This application cannot run!" 
                << std::endl;
      AoExit(0);
    }
    esriLicenseStatus status;
    ipInit->Initialize(esriLicenseProductCodeEngine, &status);
    if (status != esriLicenseCheckedOut)
    {
      std::cerr << "Invalid Licensing." << std::endl;
      AoExit(0);  
    }
  }

  XtAppContext app_context;
  SetUpForm(argc, argv, &app_context);
  
  MwCtlAppMainLoop(app_context);
}

bool OpenDocument(char* fileName)
{
  USES_CONVERSION;

  VARIANT_BOOL varbool;
  g_ipPageLayoutControl->CheckMxFile(CComBSTR(fileName), &varbool);
  if (varbool)
  {
    // Set mouse pointers
    g_ipPageLayoutControl->put_MousePointer(esriPointerHourglass);
    
    // Create a new map document
    g_ipMapDoc.CreateInstance(CLSID_MapDocument);

    // Open the map document selected
    HRESULT hr = g_ipMapDoc->Open(CComBSTR(fileName), CComBSTR(""));
    if (FAILED(hr))
      return false;

    // Set the text box to the file path of the document	 
    //   To do so we could use the name passed in -- however, for the 
    //   point of the sample we want to show the USES_CONVERSIONS macro and 
    //   get_DocumentFilename().
    CComBSTR docFileName;
    g_ipMapDoc->get_DocumentFilename(&docFileName);
    char* docName = OLE2A(docFileName);
    XmTextFieldSetString(g_currentMapText, docName);

    // Set the PageLayoutControl's page layout to the map document page layout
    IPageLayoutPtr ipPageLayout;
    g_ipMapDoc->get_PageLayout(&ipPageLayout);
    hr = g_ipPageLayoutControl->putref_PageLayout(ipPageLayout);
    if (FAILED(hr))
      return false;

    // Set mouse pointers
    g_ipPageLayoutControl->put_MousePointer(esriPointerDefault);

    return true;
  }

  ShowMessage("ERROR OPENING", "NOT A VALID ARCMAP DOCUMENT");
  return false;
}

void SaveDocumentAs(char* fileName)
{
  CComBSTR docName;
  g_ipMapDoc->get_DocumentFilename(&docName);
  if (docName == fileName)
  {
    // Save changes to the current document
    SaveDocument();
    return;
  }
  else
  {
    // SaveAs a new document with relative paths
    g_ipMapDoc->SaveAs(CComBSTR(fileName), VARIANT_TRUE, VARIANT_TRUE);
    OpenDocument(fileName);
    ShowMessage("SAVED AS", "Document saved successfully!");
  }
}

void SaveDocument()
{
  // Check that the document isn't read only
  VARIANT_BOOL vb_readOnly;
  CComBSTR docFileName;
  g_ipMapDoc->get_DocumentFilename(&docFileName);
  g_ipMapDoc->get_IsReadOnly(docFileName, &vb_readOnly);
  if (vb_readOnly)
  {
    ShowMessage("SAVE FAILED", "This map document is read only!");
    return;
  }
  
  // Save with current relative path setting
  VARIANT_BOOL vb_RelPath;
  g_ipMapDoc->get_UsesRelativePaths(&vb_RelPath);
  g_ipMapDoc->Save(vb_RelPath, VARIANT_FALSE);
  
  ShowMessage("SAVED", "Changes saved successfully!");
}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -