📄 mlview.cpp
字号:
// mlView.cpp : implementation of the CMlView class
//
#include "stdafx.h"
#include "ml.h"
#include "dlg1.h"
#include "mlDoc.h"
#include "mlView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMlView
IMPLEMENT_DYNCREATE(CMlView, CView)
BEGIN_MESSAGE_MAP(CMlView, CView)
//{{AFX_MSG_MAP(CMlView)
ON_COMMAND(IDC_CAOZUO, OnCaozuo)
ON_WM_TIMER()
ON_COMMAND(IDC_CLEAR, OnClear)
ON_WM_CREATE()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMlView construction/destruction
CMlView::CMlView()
{x=0;
y=0;
xe=0;
f=0;
j=0;
ye=0;
// TODO: add construction code here
}
CMlView::~CMlView()
{
}
BOOL CMlView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMlView drawing
void CMlView::OnDraw(CDC* pDC)
{
CMlDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
SetMOP(pDC);
pDC->TextOut (-3,-3,"0");
pDC->MoveTo(0,0);
pDC->LineTo (1000,0);
pDC->MoveTo(1000,0);
pDC->LineTo (960,20);
pDC->MoveTo(1000,0);
pDC->LineTo (960,-20);
pDC->MoveTo(0,0);
pDC->LineTo (0,800);
pDC->MoveTo (0,800);
pDC->LineTo (20,760);
pDC->MoveTo (0,800);
pDC->LineTo (-20,760);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMlView printing
BOOL CMlView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMlView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMlView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMlView diagnostics
#ifdef _DEBUG
void CMlView::AssertValid() const
{
CView::AssertValid();
}
void CMlView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMlDoc* CMlView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMlDoc)));
return (CMlDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMlView message handlers
void CMlView::OnCaozuo()
{
// TODO: Add your command handler code here
CDC *pDC=GetDC();
CDlg1 dlg;
if(dlg.DoModal()==IDOK)
{j=dlg.m_x+dlg.m_y;
xe=dlg.m_x;
ye=dlg.m_y ;
CString str;
str.Format ("你输入的坐标值为(%d,%d)",xe,ye);
pDC->SetTextColor(RGB(200,10,50));
pDC->TextOut(300,300,str);
SetMOP(pDC);
pDC->MoveTo(0,0);
pDC->LineTo (xe*100,ye*100);
SetTimer(0,1000,NULL);
}
}
void CMlView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDC *pDC;
pDC=GetDC();
SetMOP(pDC);
CPen newPen(PS_SOLID,4,RGB(200,10,20));
CPen *OldPen=pDC->SelectObject(&newPen);
pDC->MoveTo(x*100,y*100);
// TODO: 在此添加消息处理程序代码和/或调用默认值
if(j>0)
{
if(f>=0) {x=x+1;f=f-ye;}
else if(f<0) {y=y+1; f=f+xe;}
pDC->LineTo (x*100,y*100);
pDC->MoveTo(x*100,y*100);
j--;
}
else
{
KillTimer(0);
pDC->SelectObject(OldPen);
}
CView::OnTimer(nIDEvent);
}
void CMlView::SetMOP(CDC *pDC)
{pDC->SetMapMode (MM_LOMETRIC);
CRect rc;
GetClientRect(&rc);
pDC->SetViewportOrg(rc.Width ()/2,rc.Height ()/2);
}
void CMlView::OnClear()
{this->Invalidate(true);
this->x=0;
this->y=0;
this->f=0;
// TODO: Add your command handler code here
}
int CMlView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_btton.Create ("单击设置终点坐标",WS_CHILD|WS_VISIBLE,CRect(100,100,250,140),this,IDC_CAOZUO);
m_btton.ShowWindow (SW_SHOW);
m_btton1.Create ("清理",WS_CHILD|WS_VISIBLE,CRect(100,140,250,180),this,IDC_CLEAR);
m_btton1.ShowWindow (SW_SHOW);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -