Solved

MFC: WM_MOUSEWHEEL question

Posted on 2011-02-17
10
2,426 Views
Last Modified: 2012-05-11
Dear experts,

In my application, I am synchronizing two listboxes. Here is my code:
LRESULT CLineListBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
      if(message == WM_VSCROLL || message == WM_HSCROLL || message == WM_MOUSEHWHEEL)
      {
            static bool bScrollHandled = false;      // This is needed to avoid sending messages infinitely
            if(!bScrollHandled)
            {
                  m_pSiblingListBox->PostMessage(message, wParam, lParam);
                  bScrollHandled = true;
            }
            else
            {
                  bScrollHandled = false;
            }
      }
      return CListBox::WindowProc(message, wParam, lParam);
}

I am surprised to see that though synchronization works for both vertical and horizontal scroll, the mousewheel doesn't work. In fact, WM_MOUSEHWHEEL is not even caught.
Could you please help me?
Thanks.
0
Comment
Question by:tantormedia
  • 5
  • 5
10 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 34915849
Hi tantormedia,

probably the problem comes from the fact that any third-party tools catches the mouse wheel messages and translates them to i.e. scroll messages.

I.e. I had exactly the same problem with the application I'm writing on DELL PC's where Dell's 'Mouse Suite' was running - after terminating that Mouse Suite all mouse wheel messages arrived fine as expected.

Unfortunateley I never found another workaround for this except not using Dell's Mouse Suite ...

ZOPPO
0
 

Author Comment

by:tantormedia
ID: 34915857
And how that Mouse Suite can be terminated?
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 34915896
If it's the same software (Dell's Mouse Suite) you can terminate it for test via a small icon which looks like a mouse in the system tray.

BTW, the tool isn't from DELL, but I think it's pre-installed on nearly every DELL PCs and maybe on others too.

To remove it completeley you can remove 'ICO.EXE' from startup registry values ...
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:tantormedia
ID: 34916440
No, I don't think I can do that.
But I can catch the message like this:
BOOL CLineListBox::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
      static bool bMouseWheelHandled = false;      // This is needed to avoid sending messages infinitely
      if(!bMouseWheelHandled)
      {
            bMouseWheelHandled = true;
            m_pSiblingListBox->OnMouseWheel(nFlags, zDelta, pt);
      }
      else
      {
            bMouseWheelHandled = false;
      }
      return CListBox::OnMouseWheel(nFlags, zDelta, pt);
}

Do you know why I have no problems this way?
Also, when I scroll one ListBox vertically (particularly when I use mouse wheel for that), it takes the other one too long to catch up with the first one. Don't you know by any chance if this can be improved?
Thanks.
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 250 total points
ID: 34917075
Hm, sorry, I think I misunderstood this a bit - I thought the WM_MOUSEWHEEL message isn't passed to your window at all.

After some testing and looking around I think I now found the very trivial cause: It's a typo :o) in the first code you meant 'WM_MOUSEWHEEL' but wrote 'WM_MOUSEHWHEEL' which is sent by horizontal mouse wheels which I guess you don't have - at least the fact 'OnMouseWheel' indicates that this is the problem ...


About the delay with the second list box it might be it helps if you explicit update the other list box using UpdateWindow (if needed previously call InvalidateWindow).

Hope that helps,

ZOPPO
0
 

Author Comment

by:tantormedia
ID: 34917233
Thanks, it was my mistake. Now mouse wheel works... though Invalidate() and UpdateWindow() didn't help with the delay.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 34917466
ok, one more thing you can try about the delay: I think it is better to send the second list the WM_MOUSEWHEEL message (the same way as done in WindowProc from code you posted with this question) instead of calling 'OnMouseWheel' directly because what happens behind the scene when recieving the message might be quite different from what happens when calling the message handler directly ...
0
 

Author Comment

by:tantormedia
ID: 34917646
I an not sure I understand. I am not calling OnMouseWheel() directly. When you showed my mistake, I removed CLineListBox::OnMouseWheel() at all and returned to the code I posted in the beginning of the thread, only changed the misspelled message.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 34917974
ehm - sorry, I though you maybe still use this code you posted:

BOOL CLineListBox::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
      static bool bMouseWheelHandled = false;      // This is needed to avoid sending messages infinitely
      if(!bMouseWheelHandled)
      {
            bMouseWheelHandled = true;
            m_pSiblingListBox->OnMouseWheel(nFlags, zDelta, pt);
      }
      else
      {
            bMouseWheelHandled = false;
      }
      return CListBox::OnMouseWheel(nFlags, zDelta, pt);
}



Then the last idea I have is that you could try using SendMessage instead of PostMessage ...
0
 

Author Comment

by:tantormedia
ID: 34918681
No, doesn't help. Probably it is just my tough luck.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

810 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