什么是MouseEventArgs.X的类型? [英] What is the type of MouseEventArgs.X?

查看:379
本文介绍了什么是MouseEventArgs.X的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用C#工作在Visual Studio 2008(.NET 3.5)。展望 System.Windows.Forms.MouseEventArgs

Working with C# in Visual Studio 2008 (.NET 3.5). Looking into System.Windows.Forms.MouseEventArgs.

我看到奇怪的现象,长板,当我拦截处理的MouseMove 事件。看来, MouseEventArgs.X 从0到32767,然后回绕到-32768。

I'm seeing strange behavior with long Panel when I intercept handle the MouseMove event. It appears that MouseEventArgs.X goes from 0 to 32767, and wraps around to -32768.

当我看到在Visual Studio中的变量,它声称它的类型 INT

When I watch the variable in Visual Studio, it claims that it's of type int.

显然,这是一个16位有符号整数,这样它的行为。这是真的?这是一个硬性限制?

Apparently it's a 16-bit signed integer the way it's behaving. Is this true? Is this a hard limit?

谢谢!

推荐答案

这可能来自一个事实,即Windows窗体基本上以C Windows API的一个.NET包装。对于 WM_MOUSEMOVE 以及相关的消息(WM_LBUTTONDOWN,等),鼠标坐标发送在LPARAM参数。 LPARAM是一种类型定义LONG_PTR,它在32位Windows(只)是又一个typedef长。由于文档的WM_MOUSEMOVE说,你可以通过使用GET_X_LPARAM和GET_Y_LPARAM宏,返回低位int和高阶INT分别获得光标的位置。

This probably comes from the fact that Windows Forms is basically a .NET wrapper around the C Windows API. For the WM_MOUSEMOVE and related messages (WM_LBUTTONDOWN, etc.), the mouse coordinates are sent in the LPARAM parameter. LPARAM is a typedef for LONG_PTR, which on 32-bit Windows (only) is in turn a typedef for long. As the docs for WM_MOUSEMOVE say, you can get the cursor position by using the GET_X_LPARAM and GET_Y_LPARAM macros, which return the low-order int and the high-order int, respectively.

由于值是32位开始与(在32位的Windows),这是有意义的唯一方法是用于x和y坐标实际上是16位的值。基于对windowsx.h的GET_X_LPARAM的定义,我也猜(但没有,说来的官方消息),即使在64只低32位的LPARAM被用于鼠标坐标。

Since the value is 32 bits to start with (on 32-bit Windows), the only way this makes sense is for the x and y coordinates to actually be 16-bit values. Based on the definition of GET_X_LPARAM in windowsx.h, I would also guess (but do not have an official source that says) that even on x64 only the lower 32 bits of the LPARAM are used for the mouse coordinates.

这篇关于什么是MouseEventArgs.X的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆