dbaseview.cpp
资源名称:基本GIS系统开发.rar [点击查看]
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:4k
源码类别:
GIS编程
开发平台:
Visual C++
- // dbaseview.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Draw.h"
- #include "dbaseview.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDatabaseView
- IMPLEMENT_DYNCREATE(CDatabaseView, CScrollView)
- CDatabaseView::CDatabaseView()
- {
- }
- CDatabaseView::~CDatabaseView()
- {
- }
- BEGIN_MESSAGE_MAP(CDatabaseView, CScrollView)
- //{{AFX_MSG_MAP(CDatabaseView)
- ON_WM_SIZE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDatabaseView drawing
- void CDatabaseView::OnInitialUpdate()
- {
- CDrawDoc* pDoc=GetDocument(); //得到指向当前文档对象的指针
- m_pSet1=&pDoc->m_data1; //得到指向记录集合对象的指针
- CSize sizeTotal;
- // TODO: calculate the total size of this view
- Init1();
- Init2();
- CScrollView::OnInitialUpdate();
- //sizeTotal.cx = sizeTotal.cy = 100;
- SetScrollSizes(MM_TEXT, sizeTotal,sizePage,sizeLine);
- }
- void CDatabaseView::OnDraw(CDC* pDC)
- {
- // CDocument* pDoc = GetDocument();
- // TODO: add draw code here
- CDrawDoc* pDoc=GetDocument();
- // CPen pen(0,1,RGB(255,0,0));
- pDC->SetTextColor(RGB(255,0,0));
- CString c1;
- CString& c2=c1;
- pDC->SetMapMode(1);
- m_pSet1->MoveFirst();
- for(int i=0;i<nRecord;i++)
- {
- for(int j=0;j<nField;j++)
- {
- m_pSet1->GetFieldValue(j,c2);
- pDC->TextOut(nFieldStart[j],i*nCharHeight,c1);
- }
- m_pSet1->MoveNext();
- }
- }
- void CDatabaseView::Init1()
- {
- TEXTMETRIC tm;
- CDC* dc=GetDC();
- dc->GetTextMetrics(&tm);
- ReleaseDC(dc);
- nCharHeight=tm.tmHeight+2;
- nCharWidth=tm.tmAveCharWidth+2;
- if(m_pSet1->IsOpen())
- m_pSet1->Close();
- m_pSet1->Open();
- nField=m_pSet1->GetODBCFieldCount();
- CODBCFieldInfo fieldinfo1;
- CODBCFieldInfo& fieldinfo=fieldinfo1;
- for(int i=0;i<nField;i++)
- {
- m_pSet1->GetODBCFieldInfo(i,fieldinfo);
- nFieldWide[i]=(short)fieldinfo1.m_nPrecision;
- }
- nScreenWide=0;
- nFieldStart[0]=0;
- for(i=0;i<nField;i++)
- {
- nScreenWide=nScreenWide+nFieldWide[i]*nCharWidth;
- nFieldStart[i+1]=nFieldStart[i]+nFieldWide[i]*nCharWidth;
- }
- sizeTotal.cx=nScreenWide;
- sizeLine.cx=nCharWidth*5;
- }
- void CDatabaseView::Init2()
- {
- if(m_pSet1->IsOpen()) //如果打开了记录集合对象
- m_pSet1->Close();
- m_pSet1->Open();
- if(m_pSet1->IsBOF()) //如果记录指针指向记录集合范围外,即记录集合不包含记录
- nRecord=0;
- else
- {
- m_pSet1->MoveFirst();
- nRecord=0;
- while(!m_pSet1->IsBOF()) //直到指向最后一条记录范围外
- {
- m_pSet1->MoveNext();
- nRecord++;
- }
- }
- nScreenHeight=nRecord*nCharHeight;
- if(nScreenHeight==0)
- nScreenHeight=20;
- sizeTotal.cy=nScreenHeight;
- sizeLine.cy=nCharHeight+2;
- // if(nRecord>0) //添加的与编辑功能有关的代码
- // {
- // if(nIndex<1||nIndex>nRecord) //如果记录指针指向记录集合的范围外
- // nIndex=1; //将记录指针指向第一条记录
- // }
- // else
- // nIndex=-1;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDatabaseView diagnostics
- #ifdef _DEBUG
- void CDatabaseView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CDatabaseView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- CDrawDoc* CDatabaseView::GetDocument()
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrawDoc)));
- return (CDrawDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CDatabaseView message handlers
- void CDatabaseView::OnSize(UINT nType, int cx, int cy)
- {
- CScrollView::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- sizePage.cx=cx;//设置页滚动区域的宽度
- sizePage.cy=cy;//高度
- SetScrollSizes(MM_TEXT,sizeTotal,sizePage,sizeLine);//设置视图滚动范围
- }