zoukankan      html  css  js  c++  java
  • MFC绘图

    看孙鑫视频上第四章写的

    主要代码:

    void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
    {
        // TODO: 在此添加消息处理程序代码和/或调用默认值
        //MessageBox("down");
        m_ptOrigin = c_ptOld = point;
        m_bDraw = TRUE;
        CView::OnLButtonDown(nFlags, point);
    }
    
    
    void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
    {
        // TODO: 在此添加消息处理程序代码和/或调用默认值
        //MessageBox("up");
        /*
        HDC hdc = ::GetDC(m_hWnd);
        MoveToEx(hdc, m_ptOrigin.x, m_ptOrigin.y, NULL);
        LineTo(hdc, point.x, point.y);
        ::ReleaseDC(m_hWnd, hdc);
        */
        /*
        CDC *pDC = GetDC();
        pDC->MoveTo(m_ptOrigin);
        pDC->LineTo(point);
        ReleaseDC(pDC);
        */
        /*
        CClientDC dc(this);
        //CClientDC dc(GetParent());
        dc.MoveTo(m_ptOrigin);
        dc.LineTo(point);
        */
        /*
        //CWindowDC dc(this);
        //CWindowDC dc(GetParent());
        CWindowDC dc(GetDesktopWindow());
        dc.MoveTo(m_ptOrigin);
        dc.LineTo(point);
        */
        /*
        //CPen pen(PS_SOLID, 90, RGB(65, 88, 65));
        //CPen pen(PS_DASH, 1, RGB(65, 88, 65));
        CPen pen(PS_DOT, 1, RGB(65, 88, 65));
        CClientDC dc(this);
        CPen * pOldPen = dc.SelectObject(&pen);
        dc.MoveTo(m_ptOrigin);
        dc.LineTo(point);
        dc.SelectObject(pOldPen);
        */
        //CBrush brush(RGB(23, 22, 67));
        
        //CBitmap bitmap;
        //bitmap.LoadBitmap(IDB_BITMAP1);
        //CBrush brush(&bitmap);
        //CClientDC dc(this);
        //dc.FillRect(CRect(m_ptOrigin, point), &brush);
        
        /*
        CClientDC dc(this);
        CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
        CBrush *pOldBrush = dc.SelectObject(pBrush);
        dc.Rectangle(CRect(m_ptOrigin, point));
        dc.SelectObject(pOldBrush);
        */
    
        m_bDraw = FALSE;
        CView::OnLButtonUp(nFlags, point);
    }
    
    
    void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
    {
        // TODO: 在此添加消息处理程序代码和/或调用默认值
        CClientDC dc(this);
        CPen pen(PS_SOLID, 0, RGB(65, 88, 65));
        CPen *pOldPen = dc.SelectObject(&pen);
        if(m_bDraw == TRUE){
            dc.SetROP2(R2_BLACK);
            dc.MoveTo(m_ptOrigin);
            //dc.LineTo(point);
            dc.LineTo(c_ptOld);
            //dc.MoveTo(m_ptOrigin);
            dc.MoveTo(c_ptOld);
            dc.LineTo(point);
            //m_ptOrigin = point;
            c_ptOld = point;
        }
        dc.SelectObject(pOldPen);
        CView::OnMouseMove(nFlags, point);
    }

    讲了好几种方法,主要用的还是CClientDC这种的吧

  • 相关阅读:
    Serverless 解惑——函数计算如何访问 MySQL 数据库
    Kubernetes 会不会“杀死” DevOps?
    开发函数计算的正确姿势——使用交互模式安装依赖
    从零开始入门 K8s | 调度器的调度流程和算法介绍
    eclipse中如何自动生成构造函数
    微服务架构中API网关的角色
    JAVA设计模式之责任链模式
    谦先生的程序员日志之我的hadoop大数据生涯一
    谦先生的bug日志之hive启动权限问题
    CSS盒子模型之详解
  • 原文地址:https://www.cnblogs.com/louzhang/p/2690433.html
Copyright © 2011-2022 走看看