画出一个矩形,像visio那样选择它,通过拖动其顶点以实现矩形的拉伸,如何实现?

解决方案 »

  1.   

    用CRectTracker来画就可以实现了
      

  2.   

    我这里有,并且我程序里边就用到了这种技术。
    void CPWnd::OnLButtonDown(UINT nFlags, CPoint point) 
    {// Text_Hit_Text(point);
    // TODO: Add your message handler code here and/or call default
    if(!m_iPos)
    Text_Hit_Text(point);
    else
    {//已选择了
    if(m_sTr.HitTest(point) == -1)
    {//MessageBox("abc");
    m_iPos = 0;
    }
    else
    Position_Text(point);
    Invalidate();
    // CWnd::OnLButtonDown(nFlags, point);
    /// return;
    }
        SetFocus();
    if(m_iPos)
    {
    if(m_sTr.HitTest(point) == -1)
    {
    m_iPos = 0;
    }
    else
    Position_Text(point);
    Invalidate();
    CWnd::OnLButtonDown(nFlags, point);
    return;
    }
    CWnd::OnLButtonDown(nFlags, point);
    }void CPWnd::Position_Text(CPoint point)
    {
    // Start tracking the tracker rectangle.
    // Note that this function, CRectTracker::Track(), interacts with CRectTracker::AdjustRect().
    // See our CGraphTracker class for the interaction.
    if (m_sTr.Track(this, point, false,this))
    {
    // Update our new tracker rectangle dimensions.
    m_newRect.right = m_sTr.m_rect.right;//-nXOffset;
    m_newRect.left = m_sTr.m_rect.left;//-nXOffset;
    m_newRect.top = m_sTr.m_rect.top;//-nXOffset;
    m_newRect.bottom = m_sTr.m_rect.bottom;//-nXOffset;
    m_tRect.CopyRect(&m_newRect);
    m_iSChange=true;//m_iPos = 0;
    // Invalidate();
    }
    }BOOL CPWnd::Text_Hit_Text(CPoint point)
    {
    if(m_sTr.HitTest(point) == CRectTracker::hitMiddle)
    {// Set the postion flag and draw the tracker rectangle border
    m_iPos=1;
    CClientDC dc(this);
    dc.LPtoDP(m_sTr.m_rect);
    m_sTr.Draw(&dc);
    Invalidate();
    return TRUE;
    }
    return FALSE;
    }void CPWnd::OnLButtonDblClk(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    Text_Hit_Text(point);
    CWnd::OnLButtonDblClk(nFlags, point);
    }
    当然要像我程序里边哪样的话,还得稍加修改。http://shixie.topcities.com
      

  3.   

    可不可以向画图软件那样,用鼠标拖出一个矩形,再用CRectTracker实现拉伸?