c# - WindowFromPoint 在 64 位 .NET Framework 上无法正常工作

标签 c# .net winforms 64-bit

我用 C# 和 .NET 4.0 编写了简单的测试程序。

[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(int xPoint, int yPoint);

Point pt = MousePosition;
IntPtr w = WindowFromPoint(pt.X, pt.Y);

如果构建为 32 位,它就可以工作。但如果构建为 64 位,将返回一个不相关的窗口句柄。是否有解决方案或替代方案?

最佳答案

是的,那行不通。 WindowFromPoint() 接受两个参数,它只接受一个。 POINT 类型的结构。您在 32 位代码中侥幸逃脱了它,运气在 64 位模式下用完了,因为它以不同的方式传递参数。

使用 pinvoke.net 网站查找正确的 pinvoke 声明。

关于c# - WindowFromPoint 在 64 位 .NET Framework 上无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12949753/

相关文章:

c# - 为标签绘制抗锯齿椭圆区域

C# 开源 NMEA 解析器

c# - 将泛型传递到类构造函数列表中

c# - 使用 SslStream Read 方法在 C# 上挂起

.net - DataGrid 列中的列/行索引

c# - 是否可以将 FolderBrowserDialog.RootFolder 设置为字符串中的任意路径?

c# - 带有字母和数字的文本框 RTL

c# - 如何在 C#/Winforms 中将队列绑定(bind)到 DataGridView?

c# - 升级 Xamarin 表单后按钮无法立即呈现

c# - Selenium C# - 查找复杂网页中 IFrame 内的所有链接