DEALING WITH MASKED ELEMENTS

There’s still a limitation that you ought to overcome. If the element you want to move or delete is enclosed by the bounding rectangle of another element that is drawn earlier in sequence, you won’t be able to highlight it because Sketcher always finds the older element first. The older element completely masks the element it encloses. This is a result of the sequence of elements in the list. You add new elements to the back so the elements are ordered in the list from oldest to newest. You could fix this by adding a Send to Back item to the context menu that would move an element to the end of the list.

Add a separator and a menu item to the element menu in the IDR_CONTEXT_MENU resource, as shown in Figure 15-4.

The default ID will be ID_ELEMENT_SENDTOBACK, which is fine. You can try a different technique to add the message handler for the new item. You can add the handler for the item to the view class through the Properties window for the CSketcherView class. It’s best to handle it in the view because that’s where you record the selected element. Select the Events toolbar button in the Properties window for the class and double-click the message ID ID_ELEMENT_SENDTOBACK. You’ll then be able to select COMMAND and <Add>OnElementSendtoback in the right column. You can implement the handler as follows:

void CSketcherView::OnElementSendtoback() ...

Get Ivor Horton's Beginning Visual C++ 2012 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.