获取WM_NCHITTEST消息的坐标? [英] Get the coordinates of a WM_NCHITTEST message?

查看:112
本文介绍了获取WM_NCHITTEST消息的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何得到一个消息WM_NCHITTEST的坐标在C#代码?结果
我很想得到最快的方法,因为性能的要求。

How do I get the coordinates of a WM_NCHITTEST message in C# code?
I'd love to get the fastest way, because performance is a requirement.

推荐答案

从MSDN:

的wParam

此参数不被使用。

wParam
This parameter is not used.

的lParam 结果
中的低位字指定
光标的x坐标。的
坐标是相对于屏幕的
左上角。结果,
的高位字指定光标的
y坐标。在
坐标相对于屏幕的
左上角。

lParam
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.
The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.

所以,你只需要提取消息的 lParam的低阶和高阶的话:

So you just need to extract the low-order and high-order words from the message's lParam:

int x = lParam.ToInt32() & 0x0000FFFF;
int y = (int)((lParam.ToInt32() & 0xFFFF0000) >> 16)
Point pos = new Point(x, y);



我不会太担心性能,因为这些操作都只是有点水平的算术...

I wouldn't worry too much about performance, since these operations are just bit level arithmetic...

请注意,这些坐标是相对于屏幕。如果你想坐标相对于对照(或形式),你可以使用 PointToClient 方法:

Note that these coordinates are relative to the screen. If you want coordinates relative to a control (or form), you can use the PointToClient method:

Point relativePos = theControl.PointToClient(pos);

这篇关于获取WM_NCHITTEST消息的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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