OnMouseMove in CView triggers after LButtonDblClck()

Posted on 2003-02-26
Medium Priority
Last Modified: 2013-11-20
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.
Question by:milchenko
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 48

Expert Comment

ID: 8031759
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 );
LVL 22

Accepted Solution

ambience earned 800 total points
ID: 8032680
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.

Author Comment

ID: 8037321
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.
LVL 11

Expert Comment

ID: 8037697
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.

Expert Comment

ID: 8046556
remove that mouseball before doubleclicking.. :) just kidding.. :)

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question