1

在这个问题如何检测鼠标滚轮倾斜中,发布并接受了显示所需代码的答案。

我已经在我的应用程序的现有WndProc方法中实现了该代码(该方法适用于我需要捕获的其他消息),但它不起作用。我已经检查过了,WndProc似乎根本没有收到任何消息,更不用说0x020E当我倾斜鼠标滚轮时的值了。

我在安装了 .NET 3.5 SP1 的 Windows XP SP3(完全修补)上使用 Microsoft Wireless Laser 5000。

我已将 Intellipoint 驱动程序更新到 2009 年 8 月 5 日的版本 7.0.258.0。

其他应用程序(例如 Visual Studio、Word、paint.NET)正在获取并作用于倾斜的鼠标滚轮,所以它一定是我的应用程序,但我看不出我做错了什么。

为了完整起见,这是我的代码:

    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);
    }

Trace.WriteLine呼叫是尝试检查倾斜消息是否通过。正在接收WM_EXITSIZEMOVE其他消息。WM_SYSCOMMAND消息定义为:

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

注意 我删除了 [hardware] 标签,因为我 99% 确定不是硬件有问题,因为其他应用程序正在接收消息。

更新

我在我的应用程序中添加了一个带有滚动条的多行文本框,它接收鼠标滚轮倾斜消息并对其进行操作。所以我需要做的就是找到它的代码;)

更新

SuperUser 上的这个问题可能与此有关 - 我会密切关注那里的答案。

4

1 回答 1

2

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.

于 2009-07-07T15:15:23.207 回答