📄 wangview.cpp
字号:
// wangView.cpp : implementation of the CWangView class
//
#include "stdafx.h"
#include "wang.h"
#include"cutdown.h"
#include "wangDoc.h"
#include "wangView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWangView
IMPLEMENT_DYNCREATE(CWangView, CView)
BEGIN_MESSAGE_MAP(CWangView, CView)
//{{AFX_MSG_MAP(CWangView)
ON_COMMAND(ID_FILE_cut, OnFILEcut)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CWangView construction/destruction
CWangView::CWangView()
{
// TODO: add construction code here
}
CWangView::~CWangView()
{
}
BOOL CWangView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CWangView drawing
void CWangView::OnDraw(CDC* pDC)
{
CWangDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
xl=100;
xr=200;
yb=100;
yt=200;
pDC->MoveTo(xl,yb);
pDC->LineTo(xr,yb);
pDC->MoveTo(xl,yb);
pDC->LineTo(xl,yt);
pDC->MoveTo(xr,yb);
pDC->LineTo(xr,yt);
pDC->MoveTo(xl,yt);
pDC->LineTo(xr,yt);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CWangView printing
BOOL CWangView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CWangView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CWangView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CWangView diagnostics
#ifdef _DEBUG
void CWangView::AssertValid() const
{
CView::AssertValid();
}
void CWangView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CWangDoc* CWangView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWangDoc)));
return (CWangDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWangView message handlers
int CWangView::makecode( double x,double y)
{
int c=0;
if(x<xl)c=1;
else if(x>xr)c=2;
if(y<yb)c=c+4;
else if(y>yt)c=c+8;
return c;
}
void CWangView::OnFILEcut()
{
// TODO: Add your command handler code here
cutdown d;
CClientDC pDC(this);
CPen pen,*OldPen,pen2;
double x0,x2,y0,y2;
pen.CreatePen(PS_SOLID,2,RGB(255,0,0));
OldPen=pDC.SelectObject(&pen);
double m1,m2,m3,m4,n1,n2,n3,n4;
if(d.DoModal()==IDOK)
{
x0=d.m_x0; y0=d.m_y0; x2=d.m_x2; y2=d.m_y2;
int c,c1,c2;
double x,y;
c1=makecode(x0,y0);
c2=makecode(x2,y2);
while(c1!=0||c2!=0)
{
if((c1&c2)==1)return;
c=c1;if(c==0)c=c2;
if(c&1==1){y=y0+(y2-y0)*(xl-x0)/(x2-x0);x=xl;}
else if(c&2){y=y0+(y2-y0)*(xr-x0)/(x2-x0);x=xr;}
else if(c&4){x=x0+(x2-x0)*(yb-y0)/(y2-y0);y=yb;}
else if(c&8){x=x0+(x2-x0)*(yt-y0)/(y2-y0);y=yt;}
if(c==c1)
{x0=((int)x);y0=((int)y);c1=makecode(x,y);}
else
{x2=((int)x);y2=((int)y);c2=makecode(x,y);}
}
m1=d.m_x0; n1=d.m_y0;
m2=x0;n2=y0;
m3=x2;n3=y2;
m4=d.m_x2; n4=d.m_y2;
pDC.MoveTo ((int)m1,(int)n1);
pDC.LineTo ((int)m2,(int)n2);
pDC.MoveTo ((int)m3,(int)n3);
pDC.LineTo ((int)m4,(int)n4);
/* pDC.MoveTo ((int)x0,(int)y0);
pDC.LineTo ((int)x2,(int)y2);
*/
}
pDC.SelectObject(OldPen);
}
/*(1) 成员函数MoveTo:将当前的绘图位置移到point 指定的坐标处
CPoint MoveTo(int x,int y);
CPoint MoveTo(POINT point);
(2) 成员函数LineTo
在当前的绘图位置上与一个新坐标点之间画一条直线,这个新的坐标点将变成当前位置。
BOOL LineTo (int x,int y);
BOOL LineTo (POINT);
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -