使用CPen类绘制指定直线
2012-06-30 19:27
281 查看
// 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); }
相关文章推荐
- MFC中使用agg绘制直线
- C#使用GDI绘制直线的方法
- android中使用Canvas绘制指定位置和宽高度的图片
- Context3D类中的setBlendFactors方法(指定用于使用现有颜色混合绘制操作的输出颜色的系数)
- VC使用指定字体绘制文字
- 微信小程序例子——使用画布组件绘制一条长度为230px的水平直线
- C# 使用“抗锯齿”功能绘制直线和曲线
- php使用gd2绘制基本图形示例(直线、圆、正方形)
- 在MFC下绘制直线,使用橡皮筋技术,可以使直线效果跟随鼠标移
- VectorDraw Developer Framework使用教程:以指定尺寸绘制CCS轴
- 在VC中使用CPen绘制宽度大于1的虚线
- 在VC中使用CPen绘制宽度大于1的虚线
- Android使用自定义view在指定时间内匀速画一条直线的实例代码
- iOS 解决无法使用Quartz2D绘制1像素直线的问题
- 使用GDI绘制直线
- android中使用Canvas绘制指定位置和宽高度的图片
- 使用html5 Canvas绘制线条(直线、折线等)
- 使用activePDF Toolkit绘制直线
- 在VC中,使用OpenGL绘制一个矩形、三角形、三个点和三条直线,由直线组成新的三角形
- 在vc2010内使用GDI绘制直线