📄 302005.txt
字号:
// 302005人机交互View.cpp : implementation of the CMy302005View class
//
#include "stdafx.h"
#include "302005人机交互.h"
#include "302005人机交互Doc.h"
#include "302005人机交互View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy302005View
IMPLEMENT_DYNCREATE(CMy302005View, CView)
BEGIN_MESSAGE_MAP(CMy302005View, CView)
//{{AFX_MSG_MAP(CMy302005View)
ON_COMMAND(IDM_DOT, OnDot)
ON_COMMAND(IDM_LINE, OnLine)
ON_COMMAND(IDM_TRCTANGLE, OnTrctangle)
ON_COMMAND(IDM_TRIANGLE, OnTriangle)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMy302005View construction/destruction
CMy302005View::CMy302005View()
{
// TODO: add construction code here
m_nDrawType=0; //这两行为成员函数的初始化
m_ptOrigin=0;
}
CMy302005View::~CMy302005View() //析构函数,释放不必要空间
{
}
BOOL CMy302005View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMy302005View drawing
void CMy302005View::OnDraw(CDC* pDC)
{
CMy302005Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMy302005View printing
BOOL CMy302005View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMy302005View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMy302005View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMy302005View diagnostics
#ifdef _DEBUG
void CMy302005View::AssertValid() const
{
CView::AssertValid();
}
void CMy302005View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMy302005Doc* CMy302005View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy302005Doc)));
return (CMy302005Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMy302005View message handlers
void CMy302005View::OnDot()
{
// TODO: Add your command handler code here
m_nDrawType=1;
}
void CMy302005View::OnLine()
{
// TODO: Add your command handler code here
m_nDrawType=2;
}
void CMy302005View::OnTrctangle()
{
// TODO: Add your command handler code here
m_nDrawType=3;
}
void CMy302005View::OnTriangle()
{
// TODO: Add your command handler code here
m_nDrawType=4;
}
void CMy302005View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrigin=point;
CView::OnLButtonDown(nFlags, point);
}
void CMy302005View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPen pen(PS_SOLID,1,RGB(255,0,0)); //设置颜色为红色
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)); //返回CBrush的指针,利用HBRUSH为了强制转换
dc.SelectObject(pBrush); //将画刷加入表中,现在使用的是透明的画刷
switch(m_nDrawType) //当m_nDrawType分别取1,2,3,4时候分别
{ //画出不同形状的图形
case 1:
dc.SetPixel(point,RGB(255,0,0));
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);
CView::OnLButtonUp(nFlags, point);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -