Solved

MFC: WM_MOUSEWHEEL question

Posted on 2011-02-17
10
2,445 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
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 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…

809 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