0
votes

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.

1

1 Answers

1
votes

You will need to store the coordinates of the rectangle in your class (also save/load) and perform a HitTest during mouse-down.

To implement the resize handles, you will need a boolean to denote that the rectangle is selected (set boolean to FALSE if the click is not on the rectangle) and draw grab handles during paint if the boolean is TRUE; if the mouse moves over the grab handles, change the mouse-cursor, perform the resize during mouse-down and mouse-up in this case.

It's all quite complicated and gets more so if you have more than just one rectangle! Here is a DrawCLI MSDN example which does all of that with rectangles, rounded rectangles, ellipses, lines and polylines plus support for OLE -- maybe this will help, it's probably easier to delete classes/functions from DrawCLI before it's in a state to merge with your application...