// lessonMyLineView.cpp : implementation of the ClessonMyLineView class
//
#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "lessonMyLine.h"
#endif
#include "lessonMyLineDoc.h"
#include "lessonMyLineView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// ClessonMyLineView
IMPLEMENT_DYNCREATE(ClessonMyLineView, CView)
BEGIN_MESSAGE_MAP(ClessonMyLineView, CView)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &ClessonMyLineView::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
// ClessonMyLineView construction/destruction
ClessonMyLineView::ClessonMyLineView()
: m_point(0)
{
// TODO: add construction code here
}
ClessonMyLineView::~ClessonMyLineView()
{
}
BOOL ClessonMyLineView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// ClessonMyLineView drawing
void ClessonMyLineView::OnDraw(CDC* /*pDC*/)
{
ClessonMyLineDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
}
// ClessonMyLineView printing
void ClessonMyLineView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL ClessonMyLineView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void ClessonMyLineView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void ClessonMyLineView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void ClessonMyLineView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
ClientToScreen(&point);
OnContextMenu(this, point);
}
void ClessonMyLineView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// ClessonMyLineView diagnostics
#ifdef _DEBUG
void ClessonMyLineView::AssertValid() const
{
CView::AssertValid();
}
void ClessonMyLineView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
ClessonMyLineDoc* ClessonMyLineView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(ClessonMyLineDoc)));
return (ClessonMyLineDoc*)m_pDocument;
}
#endif //_DEBUG
// ClessonMyLineView message handlers
void ClessonMyLineView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_point=point;
CView::OnLButtonDown(nFlags, point);
}
void ClessonMyLineView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/* //111111111111使用MFC的CDC实现绘画
CDC *pcdc=GetDC();
pcdc->MoveTo(m_point);
pcdc->LineTo(point);
ReleaseDC(pcdc);
*/
/* //22222222222222222222使用MFC的CClentDC实现绘画
CClientDC ccdc(this);
ccdc.MoveTo(m_point);
ccdc.LineTo(point);
*/
/* //333333333333333333
//使用MFC的CWindowDC实现
//注意此时不区分客户区和功能区
//CWindowDC cwdc(GetParent());
CWindowDC cwdc(this);
cwdc.MoveTo(m_point);
cwdc.LineTo(point);
*/
CPen pen(PS_DASH,1,RGB(255,0,0));
//CPen pen(PS_SOLID,RGB(255,0,0));
CClientDC ccdc(this);
CPen *pOpen=ccdc.SelectObject(&pen);
ccdc.MoveTo(m_point);
ccdc.LineTo(point);
ccdc.SelectObject(pOpen);
CView::OnLButtonUp(nFlags, point);
}
使用CPen类绘制指定直线
最新推荐文章于 2023-03-30 19:39:10 发布