MapFormView.cpp
资源名称:vc++gps.zip [点击查看]
上传用户:jc6688
上传日期:2013-05-06
资源大小:344k
文件大小:5k
源码类别:
GPS编程
开发平台:
Visual C++
- // MapFormView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MapDemo.h"
- #include "MapDemoDoc.h"
- #include "MapView.h"
- #include "MapFormView.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMapFormView
- IMPLEMENT_DYNCREATE(CMapFormView, CFormView)
- CMapFormView::CMapFormView()
- : CFormView(CMapFormView::IDD)
- {
- //{{AFX_DATA_INIT(CMapFormView)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_pCtrlMapX=NULL;
- }
- CMapFormView::~CMapFormView()
- {
- }
- void CMapFormView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMapFormView)
- DDX_Control(pDX, IDC_MSFLEXGRID1, m_ctrlGrid);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMapFormView, CFormView)
- //{{AFX_MSG_MAP(CMapFormView)
- ON_WM_SIZE()
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMapFormView diagnostics
- #ifdef _DEBUG
- void CMapFormView::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CMapFormView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMapFormView message handlers
- void CMapFormView::OnInitialUpdate()
- {
- CMainFrame* pFrame=((CMainFrame*)AfxGetMainWnd());
- m_pMapView=pFrame->m_pMapView;
- if(m_pMapView!=NULL)
- m_pCtrlMapX=&(m_pMapView->m_ctrlMapX);
- m_strEditLayer=m_pMapView->m_strEditLayer;
- if(m_strEditLayer=="")
- {
- m_pMapView->SendMessage(WM_COMMAND,ID_MAPEDIT_SELETTABLE);
- m_strEditLayer=m_pMapView->m_strEditLayer;
- }
- CFormView::OnInitialUpdate();
- pFrame->m_pFormView=this;
- AddFormData();
- }
- void CMapFormView::OnSize(UINT nType, int cx, int cy)
- {
- CFormView::OnSize(nType, cx, cy);
- if(m_ctrlGrid.m_hWnd !=NULL)
- m_ctrlGrid.MoveWindow(0,0,cx,cy,FALSE);
- }
- void CMapFormView::OnDestroy()
- {
- CFormView::OnDestroy();
- CMainFrame* pFrame=((CMainFrame*)AfxGetMainWnd());
- pFrame->m_pFormView=NULL;
- }
- void CMapFormView::AddFormData()
- {
- CMapXLayer layer;
- m_strEditLayer=m_pMapView->m_strEditLayer;
- if(m_pCtrlMapX==NULL) return;
- if(m_strEditLayer!="")
- layer=m_pCtrlMapX->GetLayers().Item(m_strEditLayer);
- else return;
- try {
- COleVariant vtLayer;
- vtLayer.vt = VT_DISPATCH;
- vtLayer.pdispVal = layer.m_lpDispatch;
- vtLayer.pdispVal->AddRef();
- CString str1=m_strEditLayer;
- CMapXDataset dataSet;
- if(!IsInDataSet(m_strEditLayer))
- dataSet=m_pCtrlMapX->GetDatasets().Add(miDataSetLayer, vtLayer, str1);
- else
- dataSet=m_pCtrlMapX->GetDatasets().Item(str1);
- CMapXFields mapField= dataSet.GetFields();
- int cols,rows;
- cols=mapField.GetCount();
- rows=dataSet.GetRowCount();
- m_ctrlGrid.SetCols(cols+1);
- m_ctrlGrid.SetRows(rows+1);
- m_ctrlGrid.SetCol(0);
- m_ctrlGrid.SetRow(0);
- m_ctrlGrid.SetText("ͼԪID");
- for(int i=0;i<cols;i++)
- {
- CMapXField field=mapField.Item(i+1);
- CString str=field.GetName();
- m_ctrlGrid.SetCol(i+1);
- m_ctrlGrid.SetText(str);
- int nType=field.GetType();
- }//end if i
- CString str;
- //dataSet.GetLayer().BeginAccess(miAccessRead);
- for(int j=0;j<rows;j++)
- {
- str.Format("ID %d",j);
- WriteRows(-1,j,cols+1,str);
- for(i=0;i<cols;i++)
- {
- VARIANT var=dataSet.GetValue(j+1, i+1);
- COleVariant vVal(var);
- vVal.ChangeType(VT_BSTR);
- str= vVal.bstrVal;
- WriteRows(i,j,cols+1,str);
- }
- /*switch(nType)
- {
- case miTypeString:
- {
- str= vVal.bstrVal;
- }
- break;
- case miTypeNumeric:
- {
- vVal.ChangeType(VT_BSTR);
- str= vVal.bstrVal;
- }
- break;*/
- //}//end swithch
- }//end if j
- //miAccessEnd;
- // VARIANT vv=COleVariant((long)1);
- // dataSet.GetLayer().EndAccess(vv);
- //end try
- }
- catch (COleDispatchException *e) {
- e->ReportError();
- e->Delete();
- } catch (COleException *e) {
- e->ReportError();
- e->Delete();
- }
- // MessageBox("test");
- }
- void CMapFormView::WriteRows(int x, int y, int cols,CString str)
- {
- //m_ctrlGrid.SetCol(x+1);
- //m_ctrlGrid.SetRow(y+1);
- //m_ctrlGrid.SetText(str);
- int index=(y+1)*cols+x+1;
- m_ctrlGrid.SetTextArray(index, str);
- }
- BOOL CMapFormView::IsInDataSet(CString strName)
- {
- CMapXDatasets datasets=m_pCtrlMapX->GetDatasets();
- for(int i=1;i<=datasets.GetCount();i++)
- {
- if(datasets.Item(i).GetName()==strName) return TRUE;
- }
- return FALSE;
- }