?? happymaview.cpp
字號:
// happymaView.cpp : implementation of the CHappymaView class
//
#include "stdafx.h"
#include "happyma.h"
#include "happymaDoc.h"
#include "happymaView.h"
#include "DengGJ.h"
#include <stdio.h>
#include <fstream.h>
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHappymaView
IMPLEMENT_DYNCREATE(CHappymaView, CView)
BEGIN_MESSAGE_MAP(CHappymaView, CView)
//{{AFX_MSG_MAP(CHappymaView)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_DGJ, OnDgj)
ON_COMMAND(ID_SET_COLOR, OnSetColor)
ON_WM_LBUTTONDOWN()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CHappymaView construction/destruction
CHappymaView::CHappymaView()
{
// TODO: add construction code here
xty=5;
temp=0;
m_color=RGB(0,0,255);
}
CHappymaView::~CHappymaView()
{
}
BOOL CHappymaView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CHappymaView drawing
void CHappymaView::OnDraw(CDC* pDC)
{
CHappymaDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(temp)
{
Draw_H();
pDC->TextOut(300,400,"地形圖");
pDC->TextOut(400,400,"11404432 馬克");
}
}
/////////////////////////////////////////////////////////////////////////////
// CHappymaView printing
BOOL CHappymaView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CHappymaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CHappymaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CHappymaView diagnostics
#ifdef _DEBUG
void CHappymaView::AssertValid() const
{
CView::AssertValid();
}
void CHappymaView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CHappymaDoc* CHappymaView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHappymaDoc)));
return (CHappymaDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHappymaView message handlers
void CHappymaView::Draw_H()
{
FILE *ma=fopen(str,"r");
if(ma==NULL)
{
MessageBox("文件打不開!");
exit(1);
}
ifstream happy;
happy.open (str,ios::in|ios::nocreate);
if(!happy)
{
cerr<<"文件打不開!"<<endl;
exit(1);
}
char str1[10];
happy>>str1;
int ke;
happy>>ke;
double x1,x2,y1,y2;
char c;
happy>>x1>>c>>x2>>c>>y1>>c>>y2;
CClientDC dc(this);
dc.SetMapMode(MM_ANISOTROPIC);
dc.SetWindowOrg(x1+7700,y1);//設置原點坐標
dc.SetWindowExt(fabs(x1-x2)-9500,fabs(y1-y2)-2000);
dc.SetViewportExt(900,400);
CPen pen(0,10,RGB(255,0,0));
CPen *oldpen=dc.SelectObject(&pen);
dc.Rectangle(x1+7700,y1+100,x2-2400,y2-2100);
dc.SelectObject(oldpen);
while(true)
{
int mark,drawt=0;int Hdraw=0;
happy>>mark;
if(mark==0) break;
if(mark==71011) drawt=1;
else drawt=2;
float h;
happy>>h;
if(int(h)%xty==0) Hdraw=1; //做了個標記,符合的才畫
int number;
happy>>number;
float sx,sy;
char c;
happy>>sx>>c>>sy;
if(drawt==1)
{
for(int i=0;i<number-1;i++)
{
float x,y;char c;
happy>>x>>c>>y;
if(Hdraw)
{
dc.MoveTo(sx,sy);
dc.LineTo(x,y);
sx=x;
sy=y;
}
}
}
else if(drawt==2)
{
for(int j=0;j<number-1;j++)
{
float x,y;char c;
happy>>x>>c>>y;
if(Hdraw)
{
CPen pen(0,1,m_color);
CPen *oldpen=dc.SelectObject(&pen);
dc.MoveTo(sx,sy);
dc.LineTo(x,y);
sx=x;
sy=y;
dc.SelectObject(oldpen);
}
}
}
else
break;
}
}
void CHappymaView::OnFileOpen()
{
// TODO: Add your command handler code here
CFileDialog dlg(TRUE);
if(dlg.DoModal()==IDOK)
{
str=dlg.GetPathName();
temp=1;
Draw_H();
}
}
void CHappymaView::OnDgj()
{
// TODO: Add your command handler code here
CDengGJ dlg;
dlg.m_ndgjz=xty;
if(dlg.DoModal()==IDOK)
{
xty=dlg.m_ndgjz;
}
}
void CHappymaView::OnSetColor()
{
// TODO: Add your command handler code here
CColorDialog dlg;
if(dlg.DoModal()==IDOK)
m_color=dlg.GetColor();
}
void CHappymaView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Draw_H();
CView::OnLButtonDown(nFlags, point);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -