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

📄 nrdbpro.cpp

📁 一个英国人写的GIS查看/编辑工具。支持标准的shapefile地图文件格式和coverage地图文件格式。同时可以编辑相应的dbf文件。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      CString s;

      COLORREF cr = CDlgAddLayer::GetDefaultColour();
      s.Format("%i,%i,%i", GetRValue(cr), GetGValue(cr), GetBValue(cr));
      WriteProfileString(m_sDataSource, "DefaultColour", s);

   };	
  
 // Close all windows

  CloseAllDocuments(FALSE);

  // Save the map layouts

   SaveLayout();

 // Reset selections

  m_lFTypeSel = 0;
  m_aFeatureSel.RemoveAll();
  m_aAttrSel.RemoveAll();  


}

/////////////////////////////////////////////////////////////////////////////

int CNRDBApp::ExitInstance()
{    
   // Logoff

   Logout();

	return CWinApp::ExitInstance();

}

///////////////////////////////////////////////////////////////////////////////
//
// void CNRDBApp::OnAppExit() 
//
// Disconnect from the database
//

void CNRDBApp::OnAppExit() 
{

   CWinApp::OnAppExit();
}

///////////////////////////////////////////////////////////////////////////////

BOOL CNRDBApp::PreTranslateMessage(MSG* pMsg) 
{
   return CWinApp::PreTranslateMessage(pMsg);   		
}

///////////////////////////////////////////////////////////////////////////////
//
// Returns the template corresponding to the document name provided
//

CMultiDocTemplate* CNRDBApp::GetDocTemplate(LPCSTR pDocName)
{
      CMultiDocTemplate* pTemplate = NULL;
      CString strDocName;
      BOOL bFound = FALSE;

   // Search through document templates for one specified.
   // Nb. 32 bit version of foundation classes has a separate 
   // document manager class

     POSITION pos = m_pDocManager->GetFirstDocTemplatePosition();
      
      while (pos != NULL && bFound == FALSE)      
      {            
         pTemplate = (CMultiDocTemplate*)GetNextDocTemplate(pos);
         pTemplate->GetDocString(strDocName,CDocTemplate::docName);          
          
         if (strDocName == pDocName)             
         { 
            bFound = TRUE;
         }         
     }         

     if (bFound)
     { 
        return pTemplate;
     } else
     {
        return NULL;   
     };
};

///////////////////////////////////////////////////////////////////////////////

CDocMap* CNRDBApp::GetDocMap()
{
   CMultiDocTemplate* pTemplate = GetDocTemplate("Map");      

   POSITION pos = pTemplate->GetFirstDocPosition();
   if (pos != NULL)
   {
      CDocMap* pDoc = (CDocMap*)pTemplate->GetNextDoc(pos);

      ASSERT(pDoc != NULL && pDoc->IsKindOf(RUNTIME_CLASS(CDocMap)));
      return pDoc;
   }
   return NULL;
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnReportGraph() 
{
	CMultiDocTemplate* pTemplate = GetDocTemplate("Graph");      
   pTemplate->OpenDocumentFile(NULL);   	
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnReportTsgraph()  
{
	CMultiDocTemplate* pTemplate = GetDocTemplate("TSGraph");      
   pTemplate->OpenDocumentFile(NULL);   		
}

void CNRDBApp::OnReportPieChart()
{
   CMultiDocTemplate* pTemplate = GetDocTemplate("PieChart");      
   pTemplate->OpenDocumentFile(NULL);   		
}

void CNRDBApp::OnReportTSReport()
{
   CMultiDocTemplate* pTemplate = GetDocTemplate("TSReport");      
   pTemplate->OpenDocumentFile(NULL);   		
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnReportTable() 
{
   CMultiDocTemplate* pTemplate = GetDocTemplate("HtmlReport");      
   pTemplate->OpenDocumentFile(NULL);   		
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnReportSummary() 
{
   CMultiDocTemplate* pTemplate = GetDocTemplate("SummaryReport");      
   pTemplate->OpenDocumentFile(NULL);   			
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnImportODBC() 
{
	CImportDB import;
	import.ImportODBC();		   
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnImportShapefile() 
{
	CImportTextFile import;
   import.ImportShapefile();	
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnImportFile() 
{
	CImportTextFile import;
   import.ImportFile();	

   // Determine if feature types exist

   CFeatureType ftype;
   m_bFType = BDFeatureType(BDHandle(), &ftype, BDGETINIT);
   BDEnd(BDHandle());
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnReportPrevious() 
{
   m_bPreviousReport = TRUE;
   switch (m_nPreviousReport)
   {

      case CNRDB::maplayer : OnViewLayers(); break;
      case CNRDB::mapquery : OnViewLayers(); break;
      case CNRDB::standardreport : OnReportTable(); break;
      case CNRDB::reportquery : OnReportTable(); break;
      case CNRDB::summaryreport : OnReportSummary(); break;
      case CNRDB::histogram : OnReportGraph(); break;
      case CNRDB::histogramquery : OnReportGraph(); break;
      case CNRDB::timeseries : OnReportTsgraph(); break;
      case CNRDB::timeseriesquery: OnReportTsgraph(); break;
      case CNRDB::piechart : OnReportPieChart(); break;
      case CNRDB::piechartquery : OnReportPieChart(); break;
      case CNRDB::tsreport : OnReportTSReport(); break;
      case CNRDB::tsreportquery : OnReportTSReport(); break;
   }
   m_bPreviousReport = FALSE;
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnReportWizard() 
{
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnReportWizardSetup() 
{
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnViewLayers()
{
   GetDocMap()->OnLayers();
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnExportShapefile() 
{
   GetDocMap()->OnExportShapefile();
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnUpdateExportShapefile(CCmdUI* pCmdUI) 
{
   CDocMap* pDocMap = GetDocMap();
   if (pDocMap != NULL)
   {
	   int i = pDocMap->GetLayers()->GetDefault();   
      pCmdUI->Enable(i < GetDocMap()->GetLayers()->GetSize());   		
   };
}

///////////////////////////////////////////////////////////////////////////////
//
// Changes the printer to landscape.  Code taken from KB article Q126897
//

void CNRDBApp::SetLandscape()
{
   LPDEVNAMES lpDevNames;
   LPTSTR lpszDriverName, lpszDeviceName, lpszPortName;
   HANDLE hPrinter;      
   PRINTDLG   pd;

 // Get default printer settings.    PRINTDLG   pd;
   pd.lStructSize = (DWORD) sizeof(PRINTDLG);
   if (GetPrinterDeviceDefaults(&pd))
   {        // Lock memory handle.
      DEVMODE FAR* pDevMode = (DEVMODE FAR*)::GlobalLock(m_hDevMode);                 
      if (pDevMode)            
      {
            // Change printer settings in here.
            pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
           // Unlock memory handle.
         lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
         lpszDriverName = (LPTSTR )lpDevNames + lpDevNames->wDriverOffset;
         lpszDeviceName = (LPTSTR )lpDevNames + lpDevNames->wDeviceOffset;
         lpszPortName   = (LPTSTR )lpDevNames + lpDevNames->wOutputOffset;

         ::OpenPrinter(lpszDeviceName, &hPrinter, NULL);
         ::DocumentProperties(NULL,hPrinter,lpszDeviceName,pDevMode,
                           pDevMode, DM_IN_BUFFER|DM_OUT_BUFFER);

         // Sync the pDevMode.
         // See SDK help for DocumentProperties for more info.
         ::ClosePrinter(hPrinter);
         ::GlobalUnlock(m_hDevNames);
         ::GlobalUnlock(m_hDevMode);       
      }
   }
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::GetPrinterInfo(DEVMODE* pDevMode)
{
   PRINTDLG   pd;

 // Get default printer settings.    PRINTDLG   pd;
   pd.lStructSize = (DWORD) sizeof(PRINTDLG);
   if (GetPrinterDeviceDefaults(&pd))
   {        // Lock memory handle.
      DEVMODE* pDevMode1 = (DEVMODE FAR*)::GlobalLock(m_hDevMode);                 
      if (pDevMode1)            
      {
         *pDevMode = *pDevMode1;
            
         ::GlobalUnlock(m_hDevMode);       
      }
   }

}

///////////////////////////////////////////////////////////////////////////////
// App command to run the dialog
//

void CNRDBApp::OnAppAbout()
{
	CDlgAbout aboutDlg;
	aboutDlg.DoModal();
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnToolsSettings() 
{
   CSheetReportSettings dlg(IDS_REPORTSETTINGS);
   if (dlg.DoModal() == IDOK)
   {
	  m_BDMain = dlg.GetSettings();
   }
}

///////////////////////////////////////////////////////////////////////////////

BOOL CNRDBApp::ProcessMessageFilter(int code, LPMSG lpMsg)   
{
   if (m_hwndDialog != NULL)    
   {
      if (lpMsg->hwnd == m_hwndDialog ||
           ::IsChild(m_hwndDialog, lpMsg->hwnd))            
      {
         if (NULL != m_gpToolTip)
         {
             m_gpToolTip->RelayEvent(lpMsg);            
         }
      }
   }
   return CWinApp::ProcessMessageFilter(code, lpMsg);   
} 

///////////////////////////////////////////////////////////////////////////////
//
// Retrieve the default data source name, if a nrm file is specified on the
// command line
//

CString CNRDBApp::DefaultDataSource()
{
	if (m_lpCmdLine[0] != '\0')
	{
      // Strip quotes

      CString sPath = m_lpCmdLine;
      if (sPath[0] == '"')
      {
         int i = sPath.Find('"', 1);
         sPath = sPath.Mid(1, i-1);
      }
		FILE* pFile = fopen(sPath,"r");
		if (pFile != NULL)
		{
			return BDNextStr(pFile);
			fclose(pFile);
		}
	}
	return "";
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnConvertShapefile() 
{
   CShapeFile shapefile;
   shapefile.Convert();
}


///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnHelpNrdbhomepage() 
{
   m_sHtmlHelp = "http://www.nrdb.co.uk/?refer=nrdbpro200c";

   CMultiDocTemplate* pTemplate = GetDocTemplate("HtmlHelp");      
   pTemplate->OpenDocumentFile(NULL);   			   
}

void CNRDBApp::OnHelpSupport() 
{	
	
}

void CNRDBApp::OnHelpTutorial() 
{	
}


///////////////////////////////////////////////////////////////////////////////
//
// Let user choose which file type to open
//

void CNRDBApp::OnFileNew() 
{

   CDlgNew dlg;
   int nID = dlg.DoModal();
   if (nID == IDC_MAPNEW)
   {
      BeginWaitCursor();
      CDocMap* pDoc;
      CMultiDocTemplate* pTemplate = GetDocTemplate("Map");      
      pDoc = (CDocMap*)pTemplate->OpenDocumentFile(NULL);   
      EndWaitCursor();  
   } 
   else if (nID == IDC_REPORTNEW) OnReportTable();
   else if (nID == IDC_SECTORALREPORTNEW) OnReportSummary();
   else if (nID == IDC_TSREPORTNEW) OnReportTSReport();
   else if (nID == IDC_HISTOGRAMNEW) OnReportGraph();
   else if (nID == IDC_TIMESERIESGRAPHNEW) OnReportTsgraph();
   else if (nID == IDC_PIECHARTNEW) OnReportPieChart();

}

///////////////////////////////////////////////////////////////////////////////
//
// Note uses RegOpenKey rather than CRegKey::Open as bypasses NT security for
// user (need additional parameters for RegOpenKeyEx)
//

CString CNRDBApp::GetAppPath()
{
   char sRegKey[128];
   long dw;

   // Construct the file name where the report wizard file will be saved

   HKEY hKey;
   if (RegOpenKey(HKEY_CLASSES_ROOT, "nrm_auto_file\\shell\\open\\command", &hKey) == ERROR_SUCCESS)
   {
      dw = sizeof(sRegKey);
           
      if (RegQueryValue(hKey, NULL, sRegKey, &dw) == ERROR_SUCCESS)
      {
         CString s = sRegKey;
         
         s = s.Mid(1,s.ReverseFind('\\'));
         return s;
      }
   }
   RegCloseKey(hKey);
   return "";
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnFileSetupFeatureTypes() 
{
	CDlgFType dlg;
	dlg.DoModal();	

   // Determine if feature types exist

   CFeatureType ftype;
   m_bFType = BDFeatureType(BDHandle(), &ftype, BDGETINIT);
   BDEnd(BDHandle());
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnFileSetupFeatures() 
{
   CDlgFeatures dlg;
   dlg.DoModal();	
}

/////////////////////////////////////////////////////////////////////
//
// Disable menu item if the database is still empty
//

void CNRDBApp::OnUpdateFTypesExist(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_bFType);	
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::OnUpdateReportPrevious(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_nPreviousReport != -1);	
}

///////////////////////////////////////////////////////////////////////////////
//
// Retrieve the map layouts
//

void CNRDBApp::LoadLayout()
{
   // Convert xml object to scheme

   CXMLFile xmlfile;
   if (!xmlfile.Read(BDGetAppPath() + LAYOUTFILE) ||
       !m_aMapLayout.XMLAs(&xmlfile))
   {
      if (access(BDGetAppPath() + LAYOUTFILE, 00) == 0)
      {
         AfxMessageBox("Error reading: " + BDGetAppPath() + LAYOUTFILE);
         m_aMapLayout.RemoveAll();
      };
   }

   // Add default if empty
   if (m_aMapLayout.GetSize() == 0)
   {
      CMapLayout layout;
      layout.m_sName = BDString(IDS_DEFAULT);

      m_aMapLayout.Add(layout);
   };
}

///////////////////////////////////////////////////////////////////////////////

void CNRDBApp::SaveLayout()
{
   CXMLFile xmlfile;

   m_aMapLayout.AsXML(&xmlfile);
   xmlfile.Write(BDGetAppPath() + LAYOUTFILE);   
}

⌨️ 快捷键说明

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