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

📄 aotryview.cpp

📁 叮叮咚咚 叮叮咚咚 叮叮咚咚
💻 CPP
字号:
// AOTryView.cpp : implementation of the CAOTryView class
//

#include "stdafx.h"
#include "AOTry.h"

#include "AOTryDoc.h"
#include "AOTryView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAOTryView

IMPLEMENT_DYNCREATE(CAOTryView, CFormView)

BEGIN_MESSAGE_MAP(CAOTryView, CFormView)
	//{{AFX_MSG_MAP(CAOTryView)
	ON_COMMAND(IDD_OPENSHP, OnOpenshp)
	ON_COMMAND(IDD_CLEARALL, OnClearall)
	ON_WM_SIZE()
	ON_WM_CANCELMODE()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAOTryView construction/destruction

CAOTryView::CAOTryView()
	: CFormView(CAOTryView::IDD)
{
	//{{AFX_DATA_INIT(CAOTryView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here
    
}

CAOTryView::~CAOTryView()
{
}

void CAOTryView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAOTryView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BOOL CAOTryView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CAOTryView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
    CWnd *pWndCal= GetDlgItem(IDC_MAPCONTROL1);
    LPUNKNOWN pUnk=pWndCal->GetControlUnknown();
	pUnk->QueryInterface(IID_IMapControl2,(LPVOID*)&m_ipMapControl);
	m_ipMapControl->get_Map(&m_ipMap);
		 

}

/////////////////////////////////////////////////////////////////////////////
// CAOTryView printing

BOOL CAOTryView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CAOTryView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CAOTryView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CAOTryView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CAOTryView diagnostics

#ifdef _DEBUG
void CAOTryView::AssertValid() const
{
	CFormView::AssertValid();
}

void CAOTryView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CAOTryDoc* CAOTryView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAOTryDoc)));
	return (CAOTryDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CAOTryView message handlers

void CAOTryView::OnOpenshp() 
{
	// TODO: Add your command handler code here
	//BSTR strPath="F:\\ArcGIS\\gisdata\\chap11\\hucgd.aux";
//	HRESULT hr;
//	IRasterLayerPtr pRasterLy(CLSID_RasterLayer);
//	hr=pRasterLy->CreateFromFilePath(_bstr_t("F:\\temp\\cities2.bmp"));
//	if (FAILED(hr))
//	return;
//	ILayerPtr pLyr(pRasterLy);
//	m_ipMap->AddLayer(pLyr);
//	IActiveViewPtr pActiveView(m_ipMap);
//	pActiveView->Refresh();
////////////////////////////////////////////////////////////////////////////////////   
	HRESULT hr;

	IActiveViewPtr ipActiveView(m_ipMap);
   
 	IDisplayPtr pDisp(ipActiveView);
 
 	IGxDialogPtr ipGxDialog(CLSID_GxDialog);
 
 	IGxObjectFilterCollectionPtr pGxObjectFilterCollect(ipGxDialog);
 
 	IGxObjectFilterPtr ipGxObjectFilter(CLSID_GxFilterDatasets);
 
 	pGxObjectFilterCollect->AddFilter(ipGxObjectFilter,true);
 
 	IGxObjectFilterPtr pGxObjectFilter(CLSID_GxFilterFiles);
 
     pGxObjectFilterCollect->AddFilter(pGxObjectFilter,false);
 
 	ipGxDialog->put_AllowMultiSelect(VARIANT_TRUE);
 
    // ipGxDialog->put_Title(CComBSTR("选择数据"));
 
 	IEnumGxObjectPtr ipEnumGxObject;
 
 	VARIANT_BOOL bResult;
 	hr=ipGxDialog->DoModalOpen(0,&ipEnumGxObject,&bResult);
 	if (FAILED(hr))  return;
     if(bResult==VARIANT_FALSE) return;
 	hr=ipEnumGxObject->Reset();
 
 	IFeatureLayerPtr ipFeatureLayer(CLSID_FeatureLayer);
 
 	IGxObjectPtr ipGxObject;
 
 	while (!ipEnumGxObject->Next(&ipGxObject))
 	{
 		IGxDatasetPtr ipGxDataset(ipGxObject);
 		if (ipGxDataset!=0)
 		{
 			IDatasetPtr ipDataset;
 			hr=ipGxDataset->get_Dataset(&ipDataset);
 			if (FAILED(hr)) return;
 			IFeatureClassPtr ipFeatureClass(ipDataset);
 			hr=ipFeatureLayer->putref_FeatureClass(ipFeatureClass);
 			if (FAILED(hr)) return;
 			hr=ipFeatureLayer->put_Visible(VARIANT_TRUE);
 			if (FAILED(hr)) return;
             
 			ILayerPtr ipLayer(ipFeatureLayer);
 			hr=m_ipMap->AddLayer(ipLayer);
 			if (FAILED(hr)) return;
 		}
 	}
 
     IEnvelopePtr ipEnv;
 	hr=ipActiveView->get_FullExtent(&ipEnv);
 	if(FAILED(hr)) return;
 	hr= ipActiveView->put_Extent(ipEnv);
 	if (FAILED(hr)) return;
 	hr=ipActiveView->Refresh();
 	if (FAILED(hr)) return;
    
}

void CAOTryView::OnClearall() 
{
	// TODO: Add your command handler code here
	IActiveViewPtr pActiveView(m_ipMap);
	m_ipMap->ClearLayers();
    pActiveView->Refresh();
}



ILayerPtr CAOTryView::GetLayerByName(CString name)
{
  	ILayerPtr iLayer;
	long count;
	HRESULT hr;
	BSTR str;
	m_ipMap->get_LayerCount(&count);
	if(count<0)
		return NULL;
	else
		for(int i=0;i<count;i++)
		{
			hr=m_ipMap->get_Layer(i,&iLayer);
			if(FAILED(hr))  return NULL;
			iLayer->get_Name(&str);
			if(CString(str)==name)
			{
				return iLayer;
			}
		}
		return iLayer;
}

void CAOTryView::OnSize(UINT nType, int cx, int cy) 
{
	CFormView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	
	CWnd *EdintControl=GetDlgItem(IDC_EDIT1);
	CWnd *MapControl=GetDlgItem(IDC_MAPCONTROL1);
	CWnd *ButtonControl=GetDlgItem(IDC_BUTTON1);
	CWnd *StaticControl=GetDlgItem(IDC_STATIC1);
    if(EdintControl)
	{
      CRect MapControlrect;
	  MapControl->GetWindowRect(&MapControlrect);
	  CRect ButtonControlrect;
	  ButtonControl->GetWindowRect(&ButtonControlrect);
	  CRect StaticControlrect;
	  StaticControl->GetWindowRect(&StaticControlrect);
	  CRect EdintControlrect;
	  EdintControl->GetWindowRect(&EdintControlrect);
	  int iSpace=EdintControlrect.top-(MapControlrect.top+MapControlrect.Height());
	  int iYCoord=cy-EdintControlrect.Height()-iSpace;
	  int iMapHeight=iYCoord-iSpace;
	  if(iMapHeight>0)
	  {
		  ButtonControl->MoveWindow(cx-ButtonControlrect.Width(),iYCoord,
			  ButtonControlrect.Width(),ButtonControlrect.Height());

		  EdintControl->MoveWindow(EdintControlrect.left-MapControlrect.left,iYCoord,
			  EdintControlrect.Width(),EdintControlrect.Height());

		  StaticControl->MoveWindow(StaticControlrect.left-MapControlrect.left+10,iYCoord
			  ,StaticControlrect.Width(),StaticControlrect.Height());
		  MapControl->MoveWindow(0,0,cx,cy);
		
	  }

	}
}

void CAOTryView::OnCancelMode() 
{
	CFormView::OnCancelMode();
	
	// TODO: Add your message handler code here
	
}

⌨️ 快捷键说明

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