Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MFC: WM_MOUSEWHEEL question

Posted on 2011-02-17
10
Medium Priority
?
2,597 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
[X]
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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

722 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