• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

OnMouseMove in CView triggers after LButtonDblClck()

In my class derived from CView, I handle the left mouse button dbl click in the override of LButtonDblClck(). In the body of that function, I call some code to reposition the data in the view window. Alos, I handle MouseMove in override of OnMouseMove with left button pressed to implement some data processing behaviour. What I've discovered is that the OnMouseMove is triggered after the LButtonDblClck, regardless of whether the mouse was moved or not, and this introduces very unwelcome effects after double click induced in the "non-sanctioned" OnMouseMove().

Can you suggest a profound way to avoid this problem - how can I keep this OnMouseMove() event from triggering after double click, but not in other cases? I think making and checking a member variable indicating "mouse was double-clicked" and "mouse was moved after that" is not very profound and stable.
0
milchenko
Asked:
milchenko
1 Solution
 
AlexFMCommented:
Keep last mouse event point in class member:

void CMyView::OnLButtonDblClk( UINT nFlags, CPoint point )
{
    m_Point = point;

    // ...

    CView::OnLButtonDblClk(nFlags, point );
}

void CMyView::OnMouseMove( UINT nFlags, CPoint point )
{
    if ( point == m_Point )
    {
        // triggered after double click
    }

    m_Point = point;

    CView::OnMouseMove(nFlags, point );
}
0
 
ambienceCommented:
AFAIK LBUTTON_UP should come before DBL_CLICK, you muse handle LButton_Down and LButton_Up as well, in btn-down go into the data-processing mode but cancel it with btn-up.

Dbl-click should come after btn-up and thus will not interfere with data processing.
0
 
milchenkoAuthor Commented:
ambience, your way looks a bit more stable then what I've done so far (and AlexFM suggested the same), but I'm still looking for some way to avoid the problem on the message processing level. The problem with using a member variable to keep track on mouse state is the following: in the case when, say, you make a mouse-down on an application window, then switch to other window, and mouse-up is received by some other window. Or, if you keep track on the point where you double-clicked, there's always a possibity that during or immediately after double-click the mouse was moved a little, and the sequence of events will be unpredictable, and the check for the same point will not work. In other words, there's no guarantee that my member variable will always correctly track the mouse state and will always correspond to MFC framework state.
0
 
KurtVonCommented:
In OnLButtonDown do a SetCapture, in OnLButtonUp do a  ReleaseCapture.  Set a variable m_bCapture to true/false at the appropriate calls and check it when the mouse moves.  It's best not to do any data processing with an OnLButtonDown message anyway, mostly for just this reason.

AFAIK there is no simple way around this, it's just how Windows works.
0
 
PriyeshCommented:
remove that mouseball before doubleclicking.. :) just kidding.. :)
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now