CRichEditCtrl::SetRedraw() in OnMouseMove handler causes infinite loop

416 Views Asked by At

Oversimplifying, I have the next WM_MOUSEMOVE message handler in my CRichEditCtrlEx class, which is derived from the CRichEditCtrl:

void CRichEditCtrlEx::OnMouseMove(UINT nFlags, CPoint Point)
{
    SetRedraw(FALSE);
    // some actions, which should not cause rich edit redrawing
    SetRedraw(TRUE);
}

The problem is that SetRedraw(TRUE), preceded by the SetRedraw(FALSE), somehow places a new WM_MOUSEMOVE message in the message queue, so OnMouseMove handler will be called infinitely, even if the mouse doesn't move.

Trying to locate the trouble, I've experimented with the following simple handlers:

void CRichEditCtrlEx::OnMouseMove(UINT nFlags, CPoint Point)
{
    RedrawWindow();
}

or

void CRichEditCtrlEx::OnMouseMove(UINT nFlags, CPoint Point)
{
    Invalidate();
},

but they don't cause infinite loops.

I've also tried to validate the client area, but it didn't help:

void CRichEditCtrlEx::OnMouseMove(UINT nFlags, CPoint Point)
{
    SetRedraw(FALSE);
    // some actions, which should not cause rich edit redrawing
    CRect rc;
    GetClientRect(&rc);
    ValidateRect(&rc);
    SetRedraw(TRUE);
}

What is wrong with the SetRedraw()?

Any idea would be appreciated.

UPD: I see that WM_MOUSEMOVE message may be caused not only by a mouse movement, but sometimes also by a window drawing. An infinite loop can be avoided by storing the last mouse position and checking whether the mouse was really moved, but it seems for me like a workaround.

0

There are 0 best solutions below