Using SetTimer in OnMouseMove
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Using SetTimer in OnMouseMove

  1. #1
    Join Date
    Dec 2008
    Posts
    29

    Using SetTimer in OnMouseMove

    I'm using SetTimer in some functions which are causing the OnTimer function to be called correctly. However, when I use SetTimer in OnMouseMove, the OnTimer function is never called. Is this because OnMouseMove fires so many times (because the mouse is moving) that the timer message never gets processed, or is it something else?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,467

    Re: Using SetTimer in OnMouseMove

    It is because (from MSDN):
    The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue.
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,527

    Re: Using SetTimer in OnMouseMove

    Quote Originally Posted by rioch View Post
    I'm using SetTimer in some functions which are causing the OnTimer function to be called correctly. However, when I use SetTimer in OnMouseMove, the OnTimer function is never called. Is this because OnMouseMove fires so many times (because the mouse is moving) that the timer message never gets processed, or is it something else?
    Define "never". If you leave your mouse alone, would you get that OnTimer() call?
    If you set the same timer over and over every time the mouse moves (but before the timer fires) - you are effectively cancelling the previous call to SetTimer().
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  4. #4
    Join Date
    Dec 2008
    Posts
    29

    Re: Using SetTimer in OnMouseMove

    Quote Originally Posted by VictorN View Post
    It is because (from MSDN):
    I didn't notice that, thanks. I suppose that is close to the assumption I had.

    Quote Originally Posted by VladimirF View Post
    Define "never". If you leave your mouse alone, would you get that OnTimer() call?
    If you set the same timer over and over every time the mouse moves (but before the timer fires) - you are effectively cancelling the previous call to SetTimer().
    Never as in never ever. Even if I leave the mouse alone, it still doesn't fire.

    ---

    Perhaps you could suggest another option? I'm using the timer to show a custom tooltip, since the mfc tooltip framework is, in my opinion, very limited. I can get the tooltip to show and hide nicely, but once shown, it only disappears when the hide timer calls OnTimer. In the case when the mouse isn't moved, this is perfect, but if the user moves their mouse, I'd rather have the tooltip hide straight away. If I hide the window and set the state to hidden, it never shows.

    Is there a way to look at the message queue?

  5. #5
    Join Date
    Jan 2009
    Posts
    8

    Re: Using SetTimer in OnMouseMove

    Don't have a full picture about your implementation but you can try this:

    Post or Send a WM_CLOSE (or your own custom) message to the tooltip window from within OnMouseMove(). You should have a mechanism to avoid unnecessary calls to Post/Send after the tooltip is gone.

    SendMessage() doesn't return till the messge is processed by the destination window, PostMessage() posts the message and immediately returns.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center