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

📄 chinaviewview.cpp

📁 读取Blob字段(大二进制数据)的一个程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ChinaViewView.cpp : implementation of the CChinaViewView class
//

#include "stdafx.h"
#include "ChinaView.h"

#include "BaseClass.h"					//添加基类
#include "math.h"

#include "MainFrm.h"



#include "ChinaViewDoc.h"
#include "ChinaViewView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CChinaViewView

IMPLEMENT_DYNCREATE(CChinaViewView, CView)

BEGIN_MESSAGE_MAP(CChinaViewView, CView)
	//{{AFX_MSG_MAP(CChinaViewView)
	ON_WM_MOUSEMOVE()
	ON_COMMAND(ID_MAP_ZOOMIN, OnMapZoomin)
	ON_COMMAND(ID_MAP_ZOOMOUT, OnMapZoomout)
	ON_COMMAND(ID_MAP_PAN, OnMapPan)
	ON_COMMAND(ID_MAP_FULLVIEW, OnMapFullview)
	ON_UPDATE_COMMAND_UI(ID_MAP_ZOOMIN, OnUpdateMapZoomin)
	ON_UPDATE_COMMAND_UI(ID_MAP_ZOOMOUT, OnUpdateMapZoomout)
	ON_UPDATE_COMMAND_UI(ID_MAP_PAN, OnUpdateMapPan)
	ON_COMMAND(ID_VIEW_FOOTNOTE, OnViewFootnote)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FOOTNOTE, OnUpdateViewFootnote)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChinaViewView construction/destruction

CChinaViewView::CChinaViewView()
{
	dc = new CDC;
	bitmap = new CBitmap;
	Max_X = Min_X = 400;
	Max_Y = Min_Y = 200;

	times = 1;           //缩放的倍数
	buttomdown = FALSE;


	footnote = TRUE;

	Screenwidth = ::GetSystemMetrics(SM_CXSCREEN);    // 获取屏幕宽度
	Screenheight = ::GetSystemMetrics(SM_CYSCREEN);   // 获取屏幕高度


	h_Pan     = AfxGetApp()->LoadCursor(IDC_PAN);	//加载光标
	h_ZoomIn  = AfxGetApp()->LoadCursor(IDC_ZOOMIN);
	h_ZoomOut = AfxGetApp()->LoadCursor(IDC_ZOOMOUT);
	h_Arrow   = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
}

CChinaViewView::~CChinaViewView()
{
	delete dc;
	delete bitmap;
	m_object.RemoveAll();
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CChinaViewView drawing

void CChinaViewView::OnDraw(CDC* pDC)
{
	CChinaViewDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

//	ReadDataPoint();
//	ReadDataProvince();

	ClearMemScreen(pDC);
	
	DrawMapFromZB1(pDC);

	if (footnote)
	{
		DrawMapFromZJ1(pDC);
	}
	
	
	
	
}

/////////////////////////////////////////////////////////////////////////////
// CChinaViewView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CChinaViewView diagnostics

#ifdef _DEBUG
void CChinaViewView::AssertValid() const
{
	CView::AssertValid();
}

void CChinaViewView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CChinaViewView message handlers

void CChinaViewView::ReadDataPoint()
{
	CString filename = _T("CHINA.ZB1");
	
	FILE *fp;
	fp = fopen(filename,"r");
	int i;
	while (!feof(fp))
	{
		CCode *code;
		code = new CCode;
		CDoublePoint *data;
		fscanf(fp,"%d %d %d %d\n",&code->code1,&code->code2,&code->code3,&code->pointNumber);
		for (i=0;i<code->pointNumber;i++)
		{
			data = new CDoublePoint;
			fscanf(fp,"%lf %lf\n",&data->x,&data->y);
			Max_X = max(data->x,Max_X);
			Max_Y = max(data->y,Max_Y);
			Min_X = min(data->x,Min_X);
			Min_Y = min(data->y,Min_Y);
			code->m_pointArray.Add(data);
		}
		m_object.Add(code);
	}
	fclose(fp);		
	
}

//***********************************************
//函数名:DrawMapFromZB1

//功能:将ZB1文件中的数据显示在客户区

//参数说明:pDC   CDC类指针,用于绘制多边形

//返回值:无  
//***********************************************
void CChinaViewView::DrawMapFromZB1(CDC *pDC)
{
	for (int i=0;i<m_object.GetSize();i++)
	{
		CCode *pcode = m_object.GetAt(i);
		point = new CPoint[pcode->pointNumber];

		for (int j=0;j<pcode->pointNumber;j++)
		{
			CDoublePoint *temp = pcode->m_pointArray.GetAt(j);
			point[j].x = (long)((temp->x+8)*times-xmin);
			point[j].y = (long)(ymax - temp->y*times);
		}
		
		// 图廓线及岛屿(大于500者为插图)
		if (pcode->code1==10||pcode->code1==40||pcode->code1==540)  
		{
			FillPolygon(pDC,point,pcode->pointNumber,HS_DIAGCROSS,
				        RGB(128,128,0),PS_SOLID,1,RGB(255,255,255));
		}
		// 国界内普染
		else if (pcode->code1==20||pcode->code1==50||pcode->code1==550||pcode->code1==520)
		{
			FillPolygon(pDC,point,pcode->pointNumber,10,
				        RGB(82,154,16),PS_SOLID,1,RGB(120,120,0));
		}
		// 海域普染
		else if (pcode->code1==30||pcode->code1==530)
		{
			FillPolygon(pDC,point,pcode->pointNumber,10,
				        RGB(0,128,255),PS_SOLID,1,RGB(120,120,0));
		}
		// 海域国界线
		else if (pcode->code1==60||pcode->code1==560)
		{
			DrawLine(pDC,point,pcode->pointNumber,PS_INSIDEFRAME,2,RGB(255,0,0));
		}
		// 其他省界
		else if (pcode->code1==70||pcode->code1==570)
		{
			DrawLine(pDC,point,pcode->pointNumber,PS_INSIDEFRAME,1,RGB(0,0,120));
		}
		// 香港岛
		else if (pcode->code1==80||pcode->code1==580)
		{
			FillPolygon(pDC,point,pcode->pointNumber,10,
				        RGB(255,128,255),PS_SOLID,1,RGB(120,120,0));
		}
		// 河流
		else if (pcode->code1==120)
		{
			DrawLine(pDC,point,pcode->pointNumber,PS_SOLID,3,RGB(0,0,255));
		}
		// 插图廓
		else if (pcode->code1==600)
		{
			DrawLine(pDC,point,pcode->pointNumber,PS_SOLID,2,RGB(255,0,0));
		}
		// 北京
		else if (pcode->code1==101)
		{
			DrawStar(pDC,point,pcode->pointNumber,RGB(228,0,50));
		}
		// 香港、澳门
		else if (pcode->code1==100)
		{
			DrawCircle(pDC,point,pcode->pointNumber,4,RGB(0,255,64));
		}
			if (footnote)//选择显示省会城市
			{
				// 省会城市
			    if (pcode->code1==90||pcode->code1==590)
				{
					DrawCircle(pDC,point,pcode->pointNumber,5,RGB(255,0,0));
				}
			}
			
	
		delete []point;
	}
}
//***********************************************
//函数名:FillPolygon

//功能:画多边形并填充

//参数说明:pDC        CDC类指针,用于绘制多边形
//          point      存放多边形数据的数组
//          nCount     多边形数组的长度
//          index      填充模式  10:表示实填充
//          color1     填充颜色
//          penStyle   画笔形式
//          width      画笔线宽
//          color2     画笔颜色

//返回值:无  
//***********************************************
void CChinaViewView::FillPolygon(CDC *pDC, LPPOINT point, int nCount, int index, COLORREF color1, int penStyle, int width, COLORREF color2)
{
	CBrush *newBrush;
	CBrush *OldBrush;
	CPen *newPen;
	CPen *OldPen;
	if (index == 10)
	{
		newBrush = new CBrush(color1);
		OldBrush = pDC->SelectObject(newBrush);   //设置当前画刷并将原来的画刷返回到OldBrush中
		newPen = new CPen(penStyle,width,color2);
		OldPen = pDC->SelectObject(newPen);	
		
		pDC->Polygon(&point[0],nCount);           //填充多边形
		pDC->SelectObject(OldBrush);              //将画刷还原成原来的画刷
		pDC->SelectObject(OldPen);
	}
	else
	{
		COLORREF color;	        
		newBrush = new CBrush();	
		newPen = new CPen(penStyle,width,color2);
		
		//设置当前背景颜色,返回前一次的背景颜色存放在color中
		color = pDC->SetBkColor(color2);
		OldPen = pDC->SelectObject(newPen);				
		newBrush->CreateHatchBrush(index,color1); //将画刷设置成index格式
		OldBrush = pDC->SelectObject(newBrush);
		
		pDC->Polygon(&point[0],nCount);
		pDC->SelectObject(OldBrush);
		pDC->SelectObject(OldPen);

		pDC->SetBkColor(color);                  //恢复原来的背景颜色

	}
	delete newBrush;                             //释放新建的画刷
	delete newPen;
}


//***********************************************
//函数名:DrawLine

//功能:画线

//参数说明:pDC        CDC类指针,用于绘制多边形
//          point      存放多边形数据的数组
//          nCount     多边形数组的长度
//          penStyle   画笔形式
//          width      画笔线宽
//          color      画笔颜色

//返回值:无  
//***********************************************
void CChinaViewView::DrawLine(CDC *pDC, LPPOINT point, int nCount, int penStyle, int width, COLORREF color)
{
	CPen *newPen;
	CPen *OldPen;
	newPen =new CPen(penStyle,width,color);
	OldPen = pDC->SelectObject(newPen);
	pDC->MoveTo(point[0].x,point[0].y);
	for (int i=1;i<nCount;i++)
	{
		pDC->LineTo(point[i].x,point[i].y);
	}
	pDC->SelectObject(OldPen);
	delete newPen;
}


//***********************************************
//函数名:DrawCircle

//功能:画空心圆

//参数说明:pDC        CDC类指针,用于绘制多边形
//          point      存放多边形数据的数组
//          nCount     多边形数组的长度
//          radius     圆的半径
//          color      画笔颜色

//返回值:无  
//***********************************************
void CChinaViewView::DrawCircle(CDC *pDC, LPPOINT point, int nCount,int radius, COLORREF color)
{
	CPen *newPen;
	CPen *OldPen;
	newPen =new CPen(PS_SOLID,1,color);
	OldPen = pDC->SelectObject(newPen);
	pDC->Ellipse(point[0].x-radius,point[0].y-radius,point[0].x+radius,point[0].y+radius);
	pDC->SelectObject(OldPen);
	delete newPen;
}


//***********************************************
//函数名:DrawStar

//功能:画星星表示首都位置并填充

//参数说明:pDC        CDC类指针,用于绘制多边形
//          point      存放多边形数据的数组
//          nCount     多边形数组的长度
//          color      填充颜色

⌨️ 快捷键说明

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