Hello,
I have been working my way through the âSketcherâ example application beginning at the end of chapter 12. It has been going well up to chapter 15- Highlighting Elements.
My sketch elements donât highlight. Through diagnostic and breakpoints I have determined that the program flow seems correct.
The âelseâ portion of the Viewâs âOnMouseMoveâ handler (pg 734) is triggered when the mouse moves into the area of an element. It correctly identifies if the there is a change in the selected element and calls the âUpdateAllViewsâ method:
Code:
auto pOldSelected = m_pSelected; // Save any previously highlighted element
m_pSelected = GetDocument()->FindElement(point); // Not creating element.
// Are we hovering over one?
if (m_pSelected != pOldSelected)
{
// Seleceted element has changed
if (m_pSelected)
{
GetDocument()->UpdateAllViews(nullptr, 0, m_pSelected.get());
// Highlight new element if not null
RedrawWindow(); // this is the work-around I have to add
// to get Highlighting to work
}
if (pOldSelected)
{
GetDocument()->UpdateAllViews(nullptr, 0, pOldSelected.get());
// UN-Highlight previous element if not null
RedrawWindow(); // this is the work-around I have to add
}
}
What does NOT happen that I believe is supposed to, is the Viewâs âOnDrawâ handler should be called. This is not happening.
Since âOnDrawâ is not being called, none of the sketchâs elementsâ Draw methods are called.
Looking back to page 687- I could not see where in this code a WM_PAINT message was being sent- there is no call to âUpdateWindowâ in this sequence. So I added a call to âUpdateWindowâ in the code above. This had no effect on the execution- no highlighting of elements occurred.
In frustration (and curiosity) I changed that to a forced redraw with âRedrawWindowâ. This worked. My sketch elements are now highlighted when the mouse moves over them.
For whatever reason the change of color for the highlighting is not getting posted as an Invalid Area of the window, so it is not generating a redraw of the window.
Is there something missing in this example? If not, where should I look next for the problem?
Thanks