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

📄 loadmap.cpp

📁 地理信息系统ArcEngine二次开发:实现读取地图文档功能。
💻 CPP
字号:
// LoadMap.cpp : Implementation of CLoadMap
#include "stdafx.h"
#include "LoadMap.h"

/////////////////////////////////////////////////////////////////////////////
// CLoadMap

LRESULT CLoadMap::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	// center the dialog on the screen
	CenterWindow();

	// Get the IPageLayoutControl interface from the PageLayout control
	GetDlgControl(IDC_PAGELAYOUTCONTROL1, IID_IPageLayoutControl, (void **) &m_ipPLControl);
	return TRUE;  // Let the system set the focus
}

LRESULT CLoadMap::OnOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{

	USES_CONVERSION;

		// Open a file dialog for selecting map documents
	ICommonDialogPtr ipCommonDialog;
	GetDlgControl(IDC_COMMONDIALOG1, IID_ICommonDialog, (void **) &ipCommonDialog);
	ipCommonDialog->put_DialogTitle(CComBSTR("Browse Map Document"));
	ipCommonDialog->put_Filter(CComBSTR("Map Documents (*.mxd, *.mxt, *.pmf) | *.mxd; *.mxt; *.pmf"));
	ipCommonDialog->ShowOpen();

	//Exit if no map document is selected
	BSTR bstrFileName;
	ipCommonDialog->get_FileName(&bstrFileName);

	if (SysStringLen(bstrFileName) == 0) return 0;

	VARIANT_BOOL bPass;
  VARIANT_BOOL bIsMapDoc;
	IMapDocumentPtr ipMapDoc(CLSID_MapDocument);

	//Check if the map document password protected
	ipMapDoc->get_IsPasswordProtected(bstrFileName, &bPass);
	
	if (VARIANT_TRUE == bPass)
	{
		//Open password dialog as a modal dialog
		CPassword dlg2;

    // If OK button is pressed	
		if (dlg2.DoModal() == IDC_OK)
		{
			
			//Retrive password from the password dialog
			CComVariant varPassword(dlg2.m_password);

      // Wait Cursor
      m_ipPLControl->put_MousePointer(esriPointerHourglass);

			//Load Mx document
			HRESULT hr = m_ipPLControl->LoadMxFile(bstrFileName, varPassword);

      //  Default cursor
      m_ipPLControl->put_MousePointer(esriPointerDefault);

			if (FAILED(hr))
				MessageBox (_T("The Password was incorrect!"));
			else
			{	
				m_szFileName = OLE2T(bstrFileName);
				SetDlgItemText(IDC_PATH, m_szFileName);
			}
		}
	}
	else
	{
		//Check whether a file is a proper map document
		m_ipPLControl->CheckMxFile(bstrFileName, &bIsMapDoc);

		if (VARIANT_TRUE == bIsMapDoc)
		{
      // Wait Cursor
      m_ipPLControl->put_MousePointer(esriPointerHourglass);

			//Load Mx document
			m_ipPLControl->LoadMxFile(bstrFileName);
			m_szFileName = OLE2T(bstrFileName);
			SetDlgItemText(IDC_PATH, m_szFileName);

      //  Default cursor
      m_ipPLControl->put_MousePointer(esriPointerDefault);
		}
		else
		{
			MessageBox(_T("The specified file is not a valid ArcMap document"));
		}
	}
	return 0;
}

LRESULT CLoadMap::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	DestroyWindow();
  PostQuitMessage(0);  
	return 0;
}

⌨️ 快捷键说明

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