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这种的吧

  • 相关阅读:
    iOS微信支付
    iOS登录及token的业务逻辑(没怎么用过,看各种文章总结)
    IOS 支付宝支付开发流程
    iOS SDWebImage实现原理
    站立会议1
    作业六:团队项目——编写项目的Spec
    作业5
    站立会议8
    站立会议 3
    站立会议 2
  • 原文地址:https://www.cnblogs.com/louzhang/p/2690433.html
Copyright © 2011-2022 走看看