绘制连续的直线
2012-06-30 20:52
127 查看
1.首先建立MFC单文档工程lessonMyLine3.
2.在其类视图内选择lessonMyLine3View类,在其中添加消息事件“onLButtonUp”、OnLButtonDown、OnMouseMove。
3.完成上述消息内的代码。
图如下所示“
2.在其类视图内选择lessonMyLine3View类,在其中添加消息事件“onLButtonUp”、OnLButtonDown、OnMouseMove。
3.完成上述消息内的代码。
// lessonMyLine3View.cpp : implementation of the ClessonMyLine3View 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 "lessonMyLine3.h" #endif #include "lessonMyLine3Doc.h" #include "lessonMyLine3View.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // ClessonMyLine3View IMPLEMENT_DYNCREATE(ClessonMyLine3View, CView) BEGIN_MESSAGE_MAP(ClessonMyLine3View, 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, &ClessonMyLine3View::OnFilePrintPreview) ON_WM_CONTEXTMENU() ON_WM_RBUTTONUP() ON_WM_LBUTTONUP() ON_WM_LBUTTONDOWN() ON_WM_MOUSEMOVE() END_MESSAGE_MAP() // ClessonMyLine3View construction/destruction ClessonMyLine3View::ClessonMyLine3View() : m_MouseDown(false) , m_point(0) { // TODO: add construction code here } ClessonMyLine3View::~ClessonMyLine3View() { } BOOL ClessonMyLine3View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } // ClessonMyLine3View drawing void ClessonMyLine3View::OnDraw(CDC* /*pDC*/) { ClessonMyLine3Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: add draw code for native data here } // ClessonMyLine3View printing void ClessonMyLine3View::OnFilePrintPreview() { #ifndef SHARED_HANDLERS AFXPrintPreview(this); #endif } BOOL ClessonMyLine3View::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void ClessonMyLine3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void ClessonMyLine3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } void ClessonMyLine3View::OnRButtonUp(UINT /* nFlags */, CPoint point) { ClientToScreen(&point); OnContextMenu(this, point); } void ClessonMyLine3View::OnContextMenu(CWnd* /* pWnd */, CPoint point) { #ifndef SHARED_HANDLERS theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE); #endif } // ClessonMyLine3View diagnostics #ifdef _DEBUG void ClessonMyLine3View::AssertValid() const { CView::AssertValid(); } void ClessonMyLine3View::Dump(CDumpContext& dc) const { CView::Dump(dc); } ClessonMyLine3Doc* ClessonMyLine3View::GetDocument() const // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(ClessonMyLine3Doc))); return (ClessonMyLine3Doc*)m_pDocument; } #endif //_DEBUG // ClessonMyLine3View message handlers void ClessonMyLine3View::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default m_MouseDown=false; CView::OnLButtonUp(nFlags, point); } void ClessonMyLine3View::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default m_point=point; m_MouseDown=true; CView::OnLButtonDown(nFlags, point); } void ClessonMyLine3View::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CClientDC ccdc(this); if(m_MouseDown) { ccdc.MoveTo(m_point); ccdc.LineTo(point); m_point=point; } CView::OnMouseMove(nFlags, point); }
图如下所示“
相关文章推荐
- 获取或设置通过此 Pen 绘制的两条连续直线的端点的联接样式
- C# 使用“抗锯齿”功能绘制直线和曲线
- VS2012下基于Glut OpenGL绘制直线(添加设置直线宽度)示例程序:
- 简单绘制连续多个五角星
- drawRect 绘制矩形 drawCircle 绘制圆形 drawOval 绘制椭圆 drawPath 绘制任意多边形 * drawLine 绘制直线 drawPoin 绘制点
- 使用MFC进行编程,绘制直线椭圆以及样条曲线
- GDI+ 动态绘制直线
- Cocos2d-x 重写draw方法绘制直线等图形时被遮挡覆盖问题的一种解决方案
- Canvas---Canvas版画图,坐标轴绘制,网格绘制,橡皮筋式画直线
- 在win32 窗口 绘制红色直线
- 2. Quartz2D 绘制直线
- 绘制直线
- Highcharts绘制直线图
- [置顶] 【计算机图形学】【加权区域采样】用加权区域采样的方法绘制反走样直线
- 运用MATLAB绘制任意两点间的直线路径
- python绘制直线的方法
- 第三课 第一个动画:绘制直线
- 绘制余弦曲线和直线
- C++实现glut绘制点、直线、多边形、圆
- java swing-绘制2D图形,圆,矩形直线