珞珈山水BBS电脑网络程序人生 → 单文区文章阅读

单文区文章阅读 [返回]
发信人: crescentup (只谈C++), 信区: Programm
标  题: 用MFC Wizard生成单文档应用程序后
发信站: BBS 珞珈山水站 (Thu Apr 28 22:09:18 2005)

我画了一个矩形,想实现该矩形能被鼠标拖动的效果 
但是不知道为什么拖不动 
下面是问题函数
    // 矩形大小 
    const CSize m_sizeRectangle; 
    // 矩形原点坐标 
    CPoint m_pointOrg; 
    // 鼠标对原点相对偏移量 
    CSize m_sizeOffset; 
    // 鼠标是否被捕获 
    bool m_bCaptured; 

void CRectLampView::OnDraw(CDC* pDC) 

    // TODO: 在此处为本机数据添加绘制代码 
    CRect rectClient; 
    GetClientRect(rectClient); 
    pDC->SetMapMode(MM_ANISOTROPIC); 
    pDC->SetWindowExt(1000,1000); 
    pDC->SetViewportExt(rectClient.right,rectClient.bottom); 
    pDC->SetViewportOrg(rectClient.right/2,rectClient.bottom/2); 

    pDC->SelectStockObject(LTGRAY_BRUSH); 
    CPoint point(0, 0);                  // logical (0, 0) 

    pDC->LPtoDP(&point);                 // In device coordinates, 
    pDC->SetBrushOrg(point);             // align the brush with 
                                         // the window origin 
    pDC->Rectangle(-150,-150,150,150); 
      


void CRectLampView::OnLButtonDown(UINT nFlags, CPoint point) 

    CRect rectangle(-150,-150,150,150 ); // still logical 
    CRgn  rect; 

    CClientDC dc(this); 
    OnPrepareDC(&dc); 
    dc.LPtoDP(rectangle); // Now in device coordinates 
    rect.CreateRectRgnIndirect(rectangle); 
    if (rect.PtInRegion(point)) { 
        // Capturing the mouse ensures subsequent LButtonUp message 
        SetCapture(); 
        m_bCaptured = TRUE; 
        CPoint pointOrg(m_pointOrg); 
        dc.LPtoDP(&pointOrg); 
        m_sizeOffset = point - pointOrg; // device coordinates 
        // New mouse cursor is active while mouse is captured 
        ::SetCursor(::LoadCursor(NULL, IDC_CROSS)); 
    } 


void CRectView::onMouseMove(UINT nFlags, CPoint point) 

    if (m_bCaptured) { 
        CClientDC dc(this); 
    OnPrepareDC(&dc); 
    CRect rectOld(m_pointOrg,m_sizeRectangle); 
    dc.LPtoDP(rectOld); 
    InvalidateRect(rectOld, TRUE);//if masked then leaving some area behind 
    m_pointOrg = point - m_sizeOffset; 
    dc.DPtoLP(&m_pointOrg); 
    CRect rectNew(m_pointOrg, m_sizeRectangle); 
    dc.LPtoDP(rectNew); 
    InvalidateRect(rectNew, TRUE);//if masked then lost some area 
    } 


请问错在何处?谢谢了! 

--
cplusplusholic

※ 来源:·珞珈山水BBS站 http://bbs.whu.edu.cn·[FROM: 162.105.239.*]
[返回单文区目录]

武汉大学BBS 珞珈山水站 All rights reserved.
wForum , 页面执行时间:12.349毫秒