使用CPen类绘制指定直线

网友投稿 470 2022-12-02

使用CPen类绘制指定直线

使用CPen类绘制指定直线

// 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// ClessonMyLineViewIMPLEMENT_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); }

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:一个vue小demo代码介绍
下一篇:Java线程的全方位详解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~