Welcome to MSDN Blogs Sign in | Join | Help

What's with this MSH_MOUSEWHEEL message?

The hardware folks had this mouse wheel thing they were making, and they needed a way to get applications to support the mouse. Now, one way of doing this was to say, "Well, we'll start selling this wheel mouse, but no applications can use it until the next version of Windows is released, one that supports the wheel." Of course, that would have meant waiting until Windows NT 4 came out, and who know when that would be. Plus it meant that people would have to upgrade Windows in order to take advantage of their fancy new mouse. As you can imagine, they weren't too pleased with the "wait a few years" plan.

In the interim, they proposed a stopgap mechanism for applications to respond to the mouse wheel. Enter the zmouse.h header file and its MSH_MOUSEWHEEL registered message. When you installed the wheel mouse driver, it listened for wheel events from the hardware and posted this new message when the mouse wheel turned, and applications could just respond to either the WM_MOUSEWHEEL message (if running on a version of Windows that supported the message) or the MSH_MOUSEWHEEL message (if running on an older version of Windows that didn't). Unfortunately, the two messages behave differently, so it's not a simple matter of writing

if (uMsg == WM_MOUSEWHEEL || uMsg == g_msgWheel) {
 ... do wheel stuff ...
}

(These next few paragraphs summarize what is already spelled out in MSDN; you can skip them if you already know how the messages work.)

First, let's look at WM_MOUSEWHEEL. This message is delivered to the window that has focus (in the SetFocus sense). If the window procedure doesn't handle the message and just passes it through to the DefWindowProc function, then the DefWindowProc function forward the message to the window's parent. In this way, the WM_MOUSEWHEEL message automatically "bubbles outward" from the focus window up the parent chain until somebody finally handles the message (or it goes all the way to the top without being handled at all).

On the other hand, the MSH_MOUSEWHEEL message works from the outside in. It is delivered to the foreground window (in the SetForegroundWindow sense). If the window procedure doesn't want to handle the message, it can forward the message to child windows of its choice, until one of them returns TRUE to indicate that the message was handled, or until no further candidates exist.

I'll summarize these differences in a table, since people seem to like tables so much.

WM_MOUSEWHEEL MSH_MOUSEWHEEL
Propagation direction Inside-out Outside-in
Propagation mechanism DefWindowProc SendMessage
Handling Automatic Manual: Application checks return value
from child to determine what to do next
Return value if processed Zero TRUE
Return value if not processed DefWindowProc FALSE

Notice that WM_MOUSEWHEEL is much simpler, and the inside-out propagation mechanism retains the spirit of other messages such as WM_CONTEXTMENU and WM_SETCURSOR. Why can't MSH_MOUSEWHEEL do it the same way?

Well, first of all, MSH_MOUSEWHEEL doesn't have the luxury of being able to modify the DefWindowProc function. After all, that's the whole point of introducing the message in the first place, because we're trying to add wheel support to an older operating system that predated mouse wheels. Put in other words, if we could modify DefWindowProc to handle the MSH_MOUSEWHEEL message, then we wouldn't have needed the MSH_MOUSEWHEEL message to begin with; we would've just modified DefWindowProc to handle the WM_MOUSEWHEEL message.

The argument in the previous paragraph is a frustratingly common one. Given a problem X and a workaround Y, somebody will ask, "Why didn't you use method Z?" If you look at method Z, though, you'll see that it suffers from the exact same problem X.

Here's a real-world example of the "confused workaround":

"Since the I-90 bridge is closed, I can't take the 550 bus to get from Bellevue to Safeco Field. Instead, I'm going to take the 230 to Redmond, and then change to the 545."

— Well, that's silly. Why not take the 245 to Eastgate, and then change to the 554? It's a lot faster.

"Um, the 554 uses the I-90 bridge, too."

Okay, so you can't change DefWindowProc, but why not at least propagate the MSH_MOUSEWHEEL from the inside out instead of from the outside in?

Starting with the focus window assumes you can even find out what the focus window is, but if you had paid attention to the Five Things Every Win32 Programmer Should Know, you would have known that each thread has its own focus window. (Not nitpickily true, but true enough.) Consequently, when the helper program that injects MSH_MOUSEWHEEL messages calls GetFocus, it just gets its own focus window, not the focus window of the thread that controls the foreground window. (Remember, we're talking 1996, long before the GetGUIThreadInfo function was invented. History buffs can find out more from Meet The Inventor of the Mouse Wheel.) Since inside-out was off the table, that pretty much forced outside-in.

Now that you know how mouse wheel messages work, you can explain the behavior this customer is seeing:

I'm seeing the WM_MOUSEWHEEL message being delivered to the wrong child window. I have a parent window with two children. Even though I move the mouse pointer over child 1, the WM_MOUSEWHEEL goes to child 2.
Published Wednesday, August 06, 2008 7:00 AM by oldnewthing
Filed under:

Comments

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 10:39 AM by Nawak

I once had a mice that would put the focus on the child window under the pointer when you scrolled, that way you could scroll a child window without first clicking on it.

I could for instance scroll the tree folder view of explorer without first left-clicking on it and risking an 'access denied' or 'please insert a disk in drive D' etc.

That behaviour was much more logical and intuitive!

I don't see how it is more logical that left-click, right-click and middle-click all set focus and 'land' under the pointer whereas mousewheel "clicks" don't... it's not consistent with the other mouse actions. I know the mousewheel isn't just another mouse button but this behaviour is really frustrating.

I suppose it was a special mouse driver that did that and I wish windows or intellipoint could have that as well...

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 11:10 AM by roastbeef

Once, a long time ago, I was the mouse and keyboard device driver guy for OS/2 and faced the same issue of supprting mouse wheels (and the IBM Trackpoint mouse which had a thumb stick that could go every direction).

The OS/2 gui guys and the Workplace Shell group didn't wat to write any code, so I created a hack.  Moving the wheel or stick would generate synthetic up-arrow/down-arrow keystrokes.  Moving the stick left/right would also generate arrow key presses.  I even stuck in an option to generate pageup/pagedown if you really spun the wheel.

Cheesy? Yep.  But it worked as well as it could without the GUI people writing a couple of lines of code.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 12:01 PM by Pierre B.

Interesting stuff. It explains the inconsistent behavior between different applications: some scroll what has the focus, other scroll what is under the mouse.

I always find the latter behavior more intuitive as a end-user, so it seems that the "hack" to give early support to the mouse wheel and thus giving the application the choice of what will receive the wheel action is actually better.

This behavior can be implemented with the "inside-out" model, but only if all child window and control cooperate to *not* handle the event and let the higher-up logic re-distribute the user action.

Ironic, in a way.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 1:16 PM by Josh

@Nawak:  Probably not the mouse driver.  The TweakUI PowerToy enables the "Focus Follows Mouse" behavior, so your mouse driver installer may have tweaked that setting, but it's built in to Windows as a hidden option.

Get the TweakUI PowerToy, enable the XMouse option and you should be able to get that old behavior.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 1:41 PM by K

And once more, OSX manages that perfectly (altough I of course have no clue how they do it, it being not-so-open-source), mouse wheel scroll is administred to the window you *hover* over, not the window you have active. Which allows you to scroll a document (f.e. on screen two) while having eclipse open on the other screen, without losing focus for typing. Incredibly nice to have and trips me up every time I use windows.

No, I don't want to start an OS-War. I use both systems anyway (and have used Mac for a year, Windows for ten). I just can't help but to point out when the other one does it better. Recently, that has very rarely been the windows side. Competition is a good thing to have. Now someone go and rewrite bloody Explorer. Do Finder too, when you're at it, will you?

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 1:43 PM by Mike Gibson

Another in a long line of posts that basically try to use "historical realities" to explain away yet another design flaw in the Windows API.  Historically interesting...

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 1:46 PM by Darren

I never understood why they choose to send scroll wheel events to the focus window rather than the window under the mouse cursor.  I don't think you have to use a wheel mouse for very long to realize it's the wrong approach.  It's very high on list of my list of Windows annoyances.  

I remember way back when the best solution was to find a wheel mouse with a very weak wheel button that would allow you to click and scroll at the same time, thereby giving focus to the thing you're trying to scroll.  That was a fine hardware solution to a software problem, until apps started assigning separate functionality to the middle-click.

I wonder if WPF corrects this issue?

[I happen to like it that way, because I like to move my mouse out of the way so it doesn't cover what I'm reading. But apparently I'm an idiot. No news there. -Raymond]

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 2:00 PM by Ens

I prefer that the mousewheel affects the area of current mouse focus.  I don't like having to hold my mouse dead still to scroll.  But I can see how somebody might prefer the mouse tracking to follow the cursor.  But I find that aspect of OSX irritating.

Why are there scare quotes around "historical realities"?  Just call him a liar and be done with it, rather than implying it in three different ways in one-and-a-bit sentences.

[Not sure what you're getting at. Are you saying that I'm lying about the historical background? -Raymond]

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 2:12 PM by Gordon

Actually, Darren, focus should follow mouse (thanks, True X-Mouse Gizmo!), so scrolling the focus window is absolutely correct. :--)

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 2:29 PM by Plaz

I'm not sure who made the decision, but Firefox has the worst of both worlds.  It needs focus AND the mouse hovering over it for scroll.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 2:29 PM by DrkMatter

"Another in a long line of posts that basically try to use "historical realities" to explain away yet another design flaw in the Windows API.  Historically interesting..."

I can only assume that the dozens of individual who come here on a regular basis to criticize Windows and its "obvious" design flaws have the luxury to do so because, in their infinite wisdom, they have already invented the perfect OS, sold it to hundred of millions, and now whittle away their time roaming blogs from their private tropical island.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 2:38 PM by Richard

Quick survey of programs I have running right now:

Firefox: scrollwheel scrolls the window under the mouse.

MS Outlook: scrollwheel scrolls the window under the mouse.

(some Qt app): scrollwheel scrolls the window under the mouse.

Explorer in "common tasks" view: scrolls the window with focus. Common tasks pane doesn't take focus when you click it.

Good ol' consistency. Nothing like it.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 2:52 PM by Bryan Price

Nawak, I use a small program for that.  KatMouse.  It likes to play games with your wheel click, but that's a checkmark away in the preferences.  kickme.to/katmouse for the website.  I don't trust x-mouse, don't like the idea myself. :-P

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 2:53 PM by John

I don't know; this is one of those things that could be done either way.  From an end user's perspective it would make more sense to have the mouse wheel affect the window that the mouse is over.  However, this would be inconsistent with other forms of input (namely the keyboard) that send their input to the window with focus.  I think I prefer consistency in this particular case.  I run Outlook all the time but never noticed it behaved like that with the mouse wheel!  Now I will never be able to stop thinking about it.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 3:09 PM by Leo Davidson

On both XP and Vista the drivers by <the popular mouse manufacturer who isn't Microsoft> seem to get confused every so often and send the mousewheel messages to two applications at once.

Clicking around the screen a bit or closing one of the apps seems to get it back to normal. Quite annoying when it happens and the bug has been there for years. I'm pretty sure the bug is in the drivers and not Windows or the apps as it happens with multiple apps and doesn't seem to happen with other drivers.

---

"so you can't change DefWindowProc"

Was patching the current OS versions considered or is it axiomatic that one never releases fixes or features to the OS between major releases?

Obviously it would have been a lot of effort (mainly testing, I imagine) to change part of the OS between releases. However, the work/complexity saved in one place (Windows 95/NT3.11) was passed on to all the applications and vendors (including Microsoft themselves) who had to write, test and maintain two forms of wheel processing until the vendors' users stopped using the older OS versions.

(I imagine there were also political issues, like the OS team not wanting to divert resources to something that the hardware team wanted.)

I don't find it odd that what was done was done. Maybe it was the best option. But I do find it odd if changing the OS wasn't even considered and didn't have its potential costs weighed-up against definite costs of the alternative.

(Of course, I am assuming that it was known in advance that the two wheel handling systems would work differently. Perhaps it took doing it once the "wrong" way to realise that there was a better way. If the only planned change at the time was a different message name/number then it was obviously not worth changing the OS just to do that.)

[The OS team decides what OS features to update in patches. The hardware team decides what hardware to release. The two teams do not necessarily have the same priorities, especially since the OS team views the hardware team as "just another hardware vendor." -Raymond]

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 3:25 PM by Jonathan

@Plaz

Doing a quick test with IE7 shows the same behavior.  IE must be in focus AND the mouse must be over the window in order to scroll.

(Amusing trick: Always on Top windows make this behavior look odd, because if the mouse is over IE it scrolls (assuming it has focus) even if there is a window covering that part IE.)

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 3:47 PM by Ens

[Not sure what you're getting at. Are you saying that I'm lying about the historical background? -Raymond]

No, I don't think you're lying.  Sorry for the confusion.

I'm saying that the previous poster (Mike Gibson) seemed to imply that he thought you were lying, by using scare quotes on "historical background", using the terms "explain away", and the general tone of the next sentence.  I think he should either outright call you a liar, or rephrase himself to be more clear.

I'm just being Internet-peevish, though, as I recognize now that I'm more fully awake.  I should return to making ridiculously long lists of (often dubious) Canadian inventions.

Back on topic, I guess I should backpedal a bit, because within IE and FF webpages, scrolling is based on mouse location and not focus location, and I like that just fine.  Maybe I should just say, "I don't really care for consistency in my apps" and forever cease to comment on UX matters.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 7:30 PM by Dean Harding

"within IE and FF webpages, scrolling is based on mouse location and not focus location"

That's not what I'm seeing. With both IE8 & FF3, they need the keyboard focus *and* the mouse over it to scroll. If they don't have keyboard focus, they don't scroll. If the mouse is not over them, they don't scroll.

To be honest, though, I've never really noticed it myself... until it was pointed out today.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 7:37 PM by stuart

What's the distinction between MSG_MOUSEWHEEL and MSH_MOUSEWHEEL in paragraph 2, or is it a typo?

(Topic: Programmers make good proof-readers, discuss..)

ps 'ir' should be 'or'

[Both just typos. Fixed, thanks. -Raymond]

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 8:36 PM by Ulric

with regards to firefox above.  I think people say 'focus' when they mean Active.  The firefox window needs to be active to get the scrollwheel working. Then, it goes to which ever child window is under the mouse, for example the bookmark bar or the browser window.  

The inconsistency between the apps isn't actually jarring or confusing, IMHO.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 8:49 PM by AK Wong

I agree with Bryan Price about KatMouse. It's a great program and makes Explorer more usable. But if you come across any strange problems while you're running it, remember to try disabling it. You can add apps to its blacklist if they're not compatible.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 9:38 PM by DriverDude

"...the OS team views the hardware team as "just another hardware vendor."

Geez, what's the point of being a monopoly if you don't show some favortism...

oh, never mind.

Between this and the MSDN page, I can see why mouse-wheel handling is so damn inconsistent between apps. Sigh.

# re: What's with this MSH_MOUSEWHEEL message?

Wednesday, August 06, 2008 9:54 PM by DriverDude

Upon furthur reflection, it seems to me the problem is letting the hardware team design a software "solution" to support their new mouse.

For the same reason software guys should not be given soldering irons, hardware folks should not be trusted to do software.

Especially since the HW team never has to clean up the mess they create - because, obviously,  compatibility problems and WM_* are the purview of the software folks.

Ha!

# re: What's with this MSH_MOUSEWHEEL message?

Thursday, August 07, 2008 12:58 AM by Yuhong Bao

Now there is WM_MOUSEHWHEEL. I wonder why there aren't MSH_MOUSEHWHEEL?

# re: What's with this MSH_MOUSEWHEEL message?

Thursday, August 07, 2008 2:01 AM by steveg

"...the OS team views the hardware team as "just another hardware vendor."

Even if MS hardware got special treatment convincing the guys killing themselves writing NT4 to retcon a feature into the previous version of windows probably went something like: "What? A *wheel* on a *mouse*? Are you crazy? Do you have any idea the problems we're having with REAL hardware? Now you can leave, or you can make me a coffee. (muttering) Mousewheel, that'll never take off. Crazy marketing dept..."

# re: What's with this MSH_MOUSEWHEEL message?

Thursday, August 07, 2008 2:16 AM by Drak

Ahhh, so this is the reason VB6 and VSS6 don't support mouse-wheel scrolling with newer (non-ms) drivers?

I always wondered why that was. Gladly I don't have to use either anymore!

# re: What's with this MSH_MOUSEWHEEL message?

Thursday, August 07, 2008 3:04 AM by fooled me once

> The two teams do not necessarily have the same priorities, especially since the OS team views the hardware team as "just another hardware vendor."

This isn't true. The OS team cooperate more with other MS teams than with "teams" outide of the campus.

# re: What's with this MSH_MOUSEWHEEL message?

Thursday, August 07, 2008 3:15 AM by 640k

The worst thing was not choosing the "wrong" approach (focus vs foreground). The worst thing is that the behaviuor changed. Even today (ms) apps implement and overrides different behaviour.

In my opinion, the hardware team should have made a better work, and send messages to the focused window. It may be hard to implement such feature without the cooperation of the OS team, but it is not impossible. It would not even be hard to do for people who write drivers and have the resources of msft.

# re: What's with this MSH_MOUSEWHEEL message?

Thursday, August 07, 2008 5:15 AM by Dog

Firefox does have some slightly odd mouse wheel behaviour...

A quick test (FFX 3.0.1, XP Pro), shows that if any Firefox window has focus, then you can scroll any Firefox window that is under the mouse (even if that window is hosting the IE rendering engine via IETab).

Most other applications (tested IE, VS and Outlook), only scroll the currently focussed window while the mouse is over it.

I would much prefer the following the mouse behaviour if it applied system-wide.

# re: What's with this MSH_MOUSEWHEEL message?

Thursday, August 07, 2008 6:20 AM by ender

The first wheel mouse I had was Genius EasyScroll, which was AFAIK the mouse that introduced the wheel. It's drivers would always scroll the window under mouse pointer without bringing that window to foreground or focusing it. All subsequent drivers from them (for their other wheel mice) did the same, until the recently released driver that adds horrible skinned UI and a ton of useless features. I have since changed my mouse to another manufacturer, which also has fairly bloated drivers, so I skipped installation of their drivers completely, and instead configured the side buttons and old wheel behaviour with PowerPro.

BTW, if you (like me) prefer scrolling of window under cursor, and don't want to meddle with PowerPro's config files to get it working, google for KatMouse. It's freeware that basically just changes this.

# re: What's with this MSH_MOUSEWHEEL message?

Thursday, August 07, 2008 1:10 PM by KenW

@Leo: "On both XP and Vista the drivers by <the popular mouse manufacturer who isn't Microsoft> seem to get confused every so often and send the mousewheel messages to two applications at once."

Thanks for posting this. I'm glad to see it's not just me having this problem; I've been blaming it on a third-party software product I usually have open when it happens. :-)

# re: What's with this MSH_MOUSEWHEEL message?

Thursday, August 07, 2008 3:02 PM by Mike Gibson

[I think he should either outright call you a liar, or rephrase himself to be more clear.]

I don't think Raymond is lying, not at all.  My badly made point was that yet again, Raymond is attempting to blame a design flaw on history.  I'm sure he's not lying.  But history can only explain; it shouldn't excuse a poor design.

And yes I understand why Microsoft developers seem to think they're different than the rest of us who don't get to make such excuses:  Everybody uses their software.  But that makes it all the worse that they seem refuse to fix design problems and continue to blame it on history.

[The WM_MOUSEWHEEL message is incompatible with the MSH_MOUSEWHEEL message - the OS folks intentionally broke with history when they invented the new message. I guess you don't like the decision the OS team made, which is a valid point, but history wasn't a factor this time. -Raymond]

# consistency

Friday, August 08, 2008 11:57 AM by Rune

(disclaimer: I realise Raymond isn't responsible for this, and I'm not sure I'm even criticizing anyone, but I will comment nonetheless)

As others have pointed out, Outlook 2008 indeed scrolls the control underneath the mousecursor. However, there is one final catch: If the mouse leaves the application, the mousewheel instead controls the actively focused control...

I think the "Windows Design Guide" guys should chime in and make sure we're told which behaviour is the correct one.

# Inconsistency

Sunday, August 10, 2008 6:03 PM by Igor Levicki

Inconsistency is the main Windows UI issue.

Raymond said: "I happen to like it that way, because I like to move my mouse out of the way so it doesn't cover what I'm reading. But apparently I'm an idiot. No news there."

I do as well but you can still have mouse over the proper window and not blocking the text.

By the way, what happens when you have two lists side by side? Do we really have to hit the scrollbar or to click into those each time to be able to scroll them? Thats just retarded.

Another small patch that would raise usability is scrolling window content left/right when the mouse is hovering over horizontal scroll bar and wheel is used. Some applications implement that, its a really neat feature and it could have been OS default so developers of various applications don't have to reinvent the wheel.

New Comments to this post are disabled
 
Page view tracker