UI: Form editor && use CRectTracker to allow user drag/move/resize graphics

Init:

 

 m_rectTracker.m_rect.SetRect(0,0,100,100);
     m_rectTracker.m_nStyle=CRectTracker::resizeInside|CRectTracker::dottedLine;

 

 

onDraw:

 

m_rectTracker.GetTrueRect(&rect);
        //if(bDraw)
            dc.Ellipse (rect);//画椭圆;
        //Draw tracking rectangle.
        m_rectTracker.Draw(&dc);//这句画才真正的将这个四边形画出来;
 
void CRectTrackDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default
    int nIn; //定义一个鼠标的点击值;
    nIn=m_rectTracker.HitTest(point); //看看点到了哪了
    if(nIn<0)  //不在四边形区域内;
    {
        CRectTracker  temp;
        temp.TrackRubberBand(this,point,TRUE);
        temp.m_rect.NormalizeRect();
        CRectTracker interRect;
        //在建立一个CRectTracker;用于记录鼠标与椭圆的交集。
        if(interRect.m_rect.IntersectRect(temp.m_rect,m_rectTracker.m_rect))
            bDraw=TRUE; //如果有交集,则画四边形的边界,说明选择了椭圆
        else   bDraw=FALSE;
        Invalidate(); //引起OnDraw函数的发生;
    }
    else
        //在四边形区域内:
    {
        CClientDC dc(this);
        m_rectTracker.Draw(&dc);
        m_rectTracker.Track(this,point,TRUE);
        // Track()是CRectTracker中最富魅力的函数。它时时的改变调用者的m_rect;
        bDraw=TRUE;
        Invalidate();
    }

    CDialog::OnLButtonDown(nFlags, point);
}


BOOL CRectTrackDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
    // TODO: Add your message handler code here and/or call default
    if (pWnd == this && m_rectTracker.SetCursor(this, nHitTest))
          return TRUE;
    return CDialog::OnSetCursor(pWnd, nHitTest, message);
}

 

 

 

posted on 2011-03-04 20:44  cutepig  阅读(399)  评论(0编辑  收藏  举报

导航