📄 piantview.cpp
字号:
// PiantView.cpp : implementation of the CPiantView class
//
#include "stdafx.h"
#include "Piant.h"
#include "PiantDoc.h"
#include "PiantView.h"
#include "SettingDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPiantView
IMPLEMENT_DYNCREATE(CPiantView, CView)
BEGIN_MESSAGE_MAP(CPiantView, CView)
//{{AFX_MSG_MAP(CPiantView)
ON_COMMAND(IDM_DOT, OnDot)
ON_COMMAND(IDM_LINE, OnLine)
ON_COMMAND(IDM_RECT, OnRect)
ON_COMMAND(IDM_ELLIPSE, OnEllipse)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_COMMAND(IDM_SETTING, OnSetting)
ON_COMMAND(IDM_COLOR, OnColor)
ON_COMMAND(BEZIER, OnBEZIER)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CPiantView construction/destruction
CPiantView::CPiantView()
{
//成员函数的初始化
// TODO: add construction code here
m_nDrawType=0;
m_ptOrigin=0;
m_nLineWidth=0;
m_nLineStyle=0;
m_clr=RGB(0,0,0);
}
CPiantView::~CPiantView()
{
}
BOOL CPiantView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CPiantView drawing
void CPiantView::OnDraw(CDC* pDC)
{
CPiantDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CPiantView printing
BOOL CPiantView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CPiantView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CPiantView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CPiantView diagnostics
#ifdef _DEBUG
void CPiantView::AssertValid() const
{
CView::AssertValid();
}
void CPiantView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CPiantDoc* CPiantView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPiantDoc)));
return (CPiantDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPiantView message handlers
void CPiantView::OnDot()
{
// TODO: Add your command handler code here
m_nDrawType=1;
}
void CPiantView::OnLine()
{
// TODO: Add your command handler code here
m_nDrawType=2;
}
void CPiantView::OnRect()
{
// TODO: Add your command handler code here
m_nDrawType=3;
}
void CPiantView::OnEllipse()
{
// TODO: Add your command handler code here
m_nDrawType=4;
}
void CPiantView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrigin=point;
CView::OnLButtonDown(nFlags, point);
}
void CPiantView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPen pen(m_nLineStyle,m_nLineWidth,m_clr);
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
dc.SelectObject(pBrush);
//根据绘图类型的选择画不同类型的图形
switch(m_nDrawType)
{
case 1:
dc.SetPixel(point,m_clr);//设置象素点颜色为红色
break;
case 2: //画直线
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
break;
case 3: //画矩形
dc.Rectangle(CRect(m_ptOrigin,point));
break;
case 4: //画椭圆
dc.Ellipse(CRect(m_ptOrigin,point));
break;
}
CView::OnLButtonUp(nFlags, point);
}
void CPiantView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CView::OnMouseMove(nFlags, point);
}
void CPiantView::OnSetting()
{
// TODO: Add your command handler code here
CSettingDlg dlg;
dlg.m_nLineWidth=m_nLineWidth;
dlg.m_nLineStyle=m_nLineStyle;//将值传回编辑框中
if(IDOK==dlg.DoModal())
{
m_nLineWidth=dlg.m_nLineWidth;
m_nLineStyle=dlg.m_nLineStyle;
}
}
void CPiantView::OnColor()
{
// TODO: Add your command handler code here
CColorDialog dlg;
if(IDOK==dlg.DoModal())
{
m_clr=dlg.m_cc.rgbResult;
}
}
void CPiantView::OnBEZIER()
{
// TODO: Add your command handler code here
double Qx[10],Qy[10];
int i,k,l;
double Px[10]={1,2,3,4,5,6,7,8,9,10};
double Py[10]={10,9,8,7,6,5,4,3,2,1};
double u[10]={0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.25};
for(i=0;i<10;i++)
{
Qx[10]=Px[10];
Qy[10]=Py[10];
}
for(l=1;l<10;l++)
for(k=1;k<10;k++)
for(i=0;i<10;k++)
{
Qx[i]=(1.0-u)*Qx[i]+u*Qx[i+1];
Qy[i]=(1.0-u)*Qy[i]+u*Qy[i+1];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -