views:

613

answers:

1

In this question How to detect mouse wheel tilt an answer is posted and accepted that shows the code needed.

I've implemented that code in my application's existing WndProc method (which is working for other messages I need to trap) but it's not working. I've checked and WndProc doesn't appear to be getting any messages at all let alone ones with a value of 0x020E when I tilt the mouse wheel.

I'm using a Microsoft Wireless Laser 5000 on Windows XP SP3 (fully patched) with .NET 3.5 SP1 installed.

I've updated my Intellipoint drivers to version 7.0.258.0 dated 08/05/2009.

Other applications (e.g. Visual Studio, Word, paint.NET) are getting and acting upon the mouse wheel being tilted so it must be my application, but I can't see what I'm doing wrong.

Just for completeness here's my code:

    protected override void WndProc(ref Message m)
    {
        Trace.WriteLine(string.Format("0x{0:X4}", m.Msg));
        switch(m.Msg)
        {
            case WM_EXITSIZEMOVE:
                Opacity = 1.0;
                break;
            case WM_SYSCOMMAND:
                int command = m.WParam.ToInt32() & 0xfff0;
                if (command == SC_MINIMIZE && this.minimizeToTray)
                {
                    MinimizeToTray();
                }
                break;
            case WM_MOUSEHWHEEL:
                // Handle tilting here
                break;
        }
        base.WndProc(ref m);
    }

The Trace.WriteLine call is an attempt to check if the tilt messages are getting through. The other messages WM_EXITSIZEMOVE and WM_SYSCOMMAND are being received. The messages are defined as:

    private const int WM_EXITSIZEMOVE = 0x0232;
    private const int WM_SYSCOMMAND = 0x0112;
    private const int SC_MINIMIZE = 0xF020;
    private const int WM_MOUSEHWHEEL = 0x020E;

NOTE I removed the [hardware] tag, as I'm 99% sure it's not the hardware that's at fault as other applications are receiving the messages.

UPDATE

I've added a multi-line textbox with scrollbars to my application and that receives and acts upon the mouse wheel tilt messages. So all I need to do is find the code for that ;)

UPDATE

This question on SuperUser may have some bearing on this - I'll keep an eye on answers there.

A: 

Use Spy++ to check what messages you are receiving.

EDIT: You can also call m.ToString() in you WndProc method to get the name (!) of the message you've received. (This is done by a giant switch statement in Syetm.Windows.Forms.MessageDecoder.MsgToString)

Note that the messages might be sent only to whatever control has focus and not to the form itself; if that is the case, you might want to use a message filter.

Also, note that different mice send different mousewheel messages. I have a Logitech mouse that sends 0x20E with a WParam that is negative for left scroll and positive for right scroll.


EDIT (in reponse to comments)

Remember that horizontal scrolling was added long after vertical scrolling and is not supported by older programs. Therefore, the mouse driver could well be looking for horizontal scrollbars and scrolling them explicitly. Try adding a horizontal scrollbar to your form, positioned negatively so the user won't see it, and see if that changes anything.

SLaks
Other messages appear to be being sent to the form - mouse clicks etc - but I'll check this out.
ChrisF
Tilt wheel messages are sent by the mouse driver, not Windows itself (AFAIK), so they might behave differently. Spy++ can search through all child windows too (Logging Options)
SLaks
MessageDecoder.MsgToString doesn't appear to exist in .NET 3.5.
ChrisF
It's an internal type; it is called by Message.ToString
SLaks
You can see it in Reflector or the .Net Reference Source.
SLaks
The message value is definitely 0x020E as I can see it being logged when I use Spy++ on Visual Studio
ChrisF
@SLaks - Cheers, I've got the message name being output now.
ChrisF
And your program isn't receiving the message at all?
SLaks
@SLaks - No, the message isn't being received at all (as far as I can tell). Do I need a control that can have scroll bars? If so it's not consistent because I get the vertical scroll messages.
ChrisF
Tried adding a scroll bar - it didn't make any difference. Maybe it has to be a control that can have scrollbars rather than just a floating one?
ChrisF