Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MFC: WM_MOUSEWHEEL question

Posted on 2011-02-17
10
Medium Priority
?
2,652 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
Independent Software Vendors: 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

782 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