Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
DDALineView.cpp
Package: DDALine.rar [view]
Upload User: xmsintoyu
Upload Date: 2022-05-05
Package Size: 9731k
Code Size: 4k
Category:
Graph Drawing
Development Platform:
Visual C++
- // DDALineView.cpp : implementation of the CDDALineView class
- //
- #include "stdafx.h"
- #include "DDALine.h"
- #include "newDialog.h"
- #include "DDALineDoc.h"
- #include "DDALineView.h"
- #include <String.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDDALineView
- IMPLEMENT_DYNCREATE(CDDALineView, CView)
- BEGIN_MESSAGE_MAP(CDDALineView, CView)
- //{{AFX_MSG_MAP(CDDALineView)
- ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
- //}}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()
- /////////////////////////////////////////////////////////////////////////////
- // CDDALineView construction/destruction
- CDDALineView::CDDALineView()
- {
- // TODO: add construction code here
- }
- CDDALineView::~CDDALineView()
- {
- }
- BOOL CDDALineView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDDALineView drawing
- void CDDALineView::OnDraw(CDC* pDC)
- {
- CDDALineDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- int width=::GetSystemMetrics(SM_CXSCREEN);
- int height=::GetSystemMetrics(SM_CYSCREEN);
- int xtemp=40;
- int ytemp;
- int pos=0;
- CString str;
- //绘制横线
- for(ytemp=height-160;ytemp>=0;ytemp-=40)
- {
- pDC->MoveTo(xtemp,ytemp);
- pDC->LineTo(width,ytemp);
- str.Format("%d",pos); //标写坐标
- pDC->TextOut(16,ytemp-6,str);
- pos++;
- }
- //绘制竖线
- ytemp=height-160;
- pos=0;
- for(xtemp=40;xtemp<=width;xtemp+=40)
- {
- pDC->MoveTo(xtemp,0);
- pDC->LineTo(xtemp,ytemp);
- str.Format("%d",pos); //标写坐标
- pDC->TextOut(xtemp-6,height-150,str);
- pos++;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDDALineView printing
- BOOL CDDALineView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CDDALineView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CDDALineView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDDALineView diagnostics
- #ifdef _DEBUG
- void CDDALineView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CDDALineView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CDDALineDoc* CDDALineView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDDALineDoc)));
- return (CDDALineDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CDDALineView message handlers
- void CDDALineView::OnMenuitem32771()
- {
- Invalidate();
- CDDALineDoc* pDoc = (CDDALineDoc*) GetDocument();
- newDialog ip;
- if(ip.DoModal()==IDOK)
- {
- pDoc->x0=ip.m_x0;
- pDoc->x1=ip.m_x1;
- pDoc->y0=ip.m_y0;
- pDoc->y1=ip.m_y1;
- }
- DDALine(pDoc->x0,pDoc->y0,pDoc->x1,pDoc->y1);
- }
- void CDDALineView::Draw(int x,int y)
- {
- int height=::GetSystemMetrics(SM_CYSCREEN);
- CDC *pDC=GetDC();
- int xx,yy;
- xx=40+40*x;
- yy=height-160-40*y;
- pDC->Ellipse(xx-10,yy-10,xx+10,yy+10);
- }
- void CDDALineView::DDALine(int x0, int y0, int x1, int y1)
- {
- int x;
- float dx,dy,y,k;
- dx=x1-x0;
- dy=y1-y0;
- k=dy/dx;
- if(k<=1 && k>=-1) //斜率小于1
- {
- y=y0;
- for(x=x0;x<=x1;x++)
- {
- Draw(x,int(y+0.5));
- y=y+k;
- }
- }
- else //斜率大于1
- {
- int yy;
- float xx;
- xx=x0;
- for(yy=y0;yy<=y1;yy++)
- {
- Draw(int(xx+0.5),yy);
- xx=xx+(1/k);
- }
- }
- }