Solved

MFC: WM_MOUSEWHEEL question

Posted on 2011-02-17
10
2,252 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 30

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 30

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
 

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 30

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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 30

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 30

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now