Why isn't my app getting mouse wheel tilt messages?

一笑奈何 提交于 2019-12-02 13:26:48

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/1092500/why-isnt-my-app-getting-mouse-wheel-tilt-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!