0

I'm trying to create an interface that allows the user to draw a rectangle over a picture control box. I have a picture control class and used CRectTracker to allow the user to draw a rectangle. I want the user to also be able to select a previously drawn rectangle but I don't know how to handle the selection of a drawn rectangle. I want to be able to select the rectangle and also add resize handlers on it.

Here is my code for drawing the rect.

void PictureCtrl::OnLButtonDown(UINT nFlags, CPoint point) {

// If mouse click is outside of rectangle
if(m_drawRect.m_tracker.HitTest(point) < 0 ) {
    if(m_drawRect.m_tracker.TrackRubberBand(this, point, TRUE)) {
        CDC* pDC = GetDC();

        m_drawRect.m_tracker.m_nStyle &= CRectTracker::resizeInside;


        // Paint transparent rectangle
        pDC->SelectStockObject(NULL_BRUSH);
        pDC->Rectangle(m_drawRect.m_tracker.m_rect);

        ReleaseDC(pDC);


    }
} 

CStatic::OnLButtonDown(nFlags, point);

}

Any help would be appreciated. Thank you.

4

1 回答 1

1

您需要将矩形的坐标存储在您的类中(也保存/加载)并HitTest在鼠标按下期间执行。

要实现调整大小手柄,您将需要一个布尔值来表示矩形已被选中(如果单击不在矩形上,则将布尔值设置为 FALSE),如果布尔值为 TRUE,则在绘制期间绘制抓取手柄;如果鼠标在抓握手柄上移动,请更改鼠标光标,在这种情况下在鼠标向下和鼠标向上期间执行调整大小。

如果你有不止一个矩形,这一切都非常复杂,而且会变得更复杂!这是一个DrawCLI MSDN 示例,它使用矩形、圆角矩形、椭圆、直线和折线以及对 OLE 的支持来完成所有这些操作——也许这会有所帮助,在 DrawCLI 处于合并状态之前删除类/函数可能更容易与您的应用程序...

于 2013-08-01T16:25:15.060 回答