我正在尝试使用 Magnification API 为 32 位 Windows 8 Pro 平板电脑 编写辅助功能应用程序。应用程序可以完美地放大和缩小全屏,但是当放大时,点击事件被发送到未放大屏幕的错误位置,因此用户无法准确触摸到他所看到的内容。
为了解决这个问题,我尝试了 MagSetInputTransform(fSetInputTransform, rcSource, rcDest)。它适用于 64 位 Windows 8 桌面,但当我在平板电脑上测试时,出现以下错误:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at GTZoom.WinAPIMethods.MagSetInputTransform(Boolean fEnabled, RECT prcSource, RECT prcDest)
at GTZoom.ZoomControl.SetInput(IntPtr hwndDlg, Boolean fSetInputTransform) in c:\Users\AlpayK\Desktop\GTMagnify\GTMagnify\ZoomControl.cs:line 113
at GTZoom.ZoomControl.trackBar1_Scroll(Object sender, EventArgs e) in c:\Users\AlpayK\Desktop\GTMagnify\GTMagnify\ZoomControl.cs:line 37
at System.Windows.Forms.TrackBar.OnScroll(EventArgs e)
at System.Windows.Forms.TrackBar.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
当我尝试为 x86 目标平台编译项目并在 64 位机器下测试时,得到了完全相同的错误。
总结一下;
Target platform x64 -> Tested under 64bit Windows 8 Desktop OK
Target platform x86 -> Tested under 64bit Windows 8 Desktop ERROR
Target platform x64 -> Tested under 64bit Windows 8 Tablet ERROR
Target platform x86 -> Tested under 32bit Windows 8 Tablet ERROR ?
如何在 32 位 Windows 8 平板电脑上使用此 WinAPI 函数?
编辑1
这是产生错误的方法:
void SetInput(IntPtr hwndDlg, bool fSetInputTransform)
{
bool fContinue = true;
RECT rcSource = new RECT();
RECT rcDest = new RECT();
// MagSetInputTransform() is used to adjust pen and touch input to account for the current magnification.
// The "Source" and "Destination" rectangles supplied to MagSetInputTransform() are from the perspective
// of the currently magnified visuals. The source rectangle is the portion of the screen that is
// currently being magnified, and the destination rectangle is the area on the screen which shows the
// magnified results.
// If we're setting an input transform, base the transform on the current fullscreen magnification.
if (fSetInputTransform)
{
// Assume here the touch and pen input is going to the primary monitor.
rcDest.Right = screenWidth;
rcDest.Bottom = screenHeight;
float magnificationFactor = 0;
int xOffset = 0;
int yOffset = 0;
// Get the currently active magnification.
if (WinAPIMethods.MagGetFullscreenTransform(ref magnificationFactor, ref xOffset, ref yOffset))
{
// Determine the area of the screen being magnified.
rcSource.Left = xOffset;
rcSource.Top = yOffset;
rcSource.Right = rcSource.Left + (int)(rcDest.Right / magnificationFactor);
rcSource.Bottom = rcSource.Top + (int)(rcDest.Bottom / magnificationFactor);
}
else
{
// An unexpected error occurred trying to get the current magnification.
fContinue = false;
}
}
if (fContinue)
{
// Now set the input transform as required.
if (!WinAPIMethods.MagSetInputTransform(fSetInputTransform, rcSource, rcDest))
{
MessageBox.Show("Err");
}
}
}
EDIT2
这是 pinvoke 签名:
[DllImport("Magnification.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagGetFullscreenTransform(ref float magLevel, ref int xOffset, ref int yOffset);
[DllImport("Magnification.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagSetInputTransform(bool fEnabled, RECT prcSource, RECT prcDest);
和this是我的 RECT 结构的样子。
最佳答案
WinAPIMethods.MagSetInputTransform(fSetInputTransform, rcSource, rcDest)
WinAPIMethods.MagSetInputTransform(fSetInputTransform, ref rcSource, ref rcDest)
和pinvoke
public static extern bool MagSetInputTransform(bool fEnabled, RECT prcSource, RECT prcDest);
public static extern bool MagSetInputTransform(bool fEnabled, ref RECT prcSource, ref RECT prcDest);
MagSetInputTransform采用 LPRECT,而不是 RECT
虽然我无法解释为什么它可以在一台机器上运行。
关于c# - 在 Windows 8 Pro 平板电脑中使用 WinAPI 抛出 AccessViolationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16807049/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub
我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha
之前在培训新生的时候,windows环境下配置opencv环境一直教的都是网上主流的vsstudio配置属性表,但是这个似乎对新生来说难度略高(虽然个人觉得完全是他们自己的问题),加之暑假之后对cmake实在是爱不释手,且这样配置确实十分简单(其实都不需要配置),故斗胆妄言vscode下配置CV之法。其实极为简单,图比较多所以很长。如果你看此文还配不好,你应该思考一下是不是自己的问题。闲话少说,直接开始。0.CMkae简介有的人到大二了都不知道cmake是什么,我不说是谁。CMake是一个开源免费并且跨平台的构建工具,可以用简单的语句来描述所有平台的编译过程。它能够根据当前所在平台输出对应的m
C#实现简易绘图工具一.引言实验目的:通过制作窗体应用程序(C#画图软件),熟悉基本的窗体设计过程以及控件设计,事件处理等,熟悉使用C#的winform窗体进行绘图的基本步骤,对于面向对象编程有更加深刻的体会.Tutorial任务设计一个具有基本功能的画图软件**·包括简单的新建文件,保存,重新绘图等功能**·实现一些基本图形的绘制,包括铅笔和基本形状等,学习橡皮工具的创建**·设计一个合理舒适的UI界面**注明:你可能需要先了解一些关于winform窗体应用程序绘图的基本知识,以及关于GDI+类和结构的知识二.实验环境Windows系统下的visualstudio2017C#窗体应用程序三.
深度学习部署:Windows安装pycocotools报错解决方法1.pycocotools库的简介2.pycocotools安装的坑3.解决办法更多Ai资讯:公主号AiCharm本系列是作者在跑一些深度学习实例时,遇到的各种各样的问题及解决办法,希望能够帮助到大家。ERROR:Commanderroredoutwithexitstatus1:'D:\Anaconda3\python.exe'-u-c'importsys,setuptools,tokenize;sys.argv[0]='"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-instal
我在目录“C:\DocumentsandSettings\test.exe”中有一个文件,但是当我用单引号编写命令时`C:\DocumentsandSettings\test.exe(我无法在此框中显示),用于在Ruby中执行命令,我无法这样做,我收到的错误是找不到文件或目录。我尝试用“//”和“\”替换“\”,但似乎没有任何效果。我也使用过系统、IO.popen和exec命令,但所有的努力都是徒劳的。exec命令还使程序退出,这是我不想发生的。提前致谢。 最佳答案 反引号环境就像双引号,所以反斜杠用于转义。此外,Ruby会将空格解
我如何做Ruby方法"Flatten"RubyMethod在C#中。此方法将锯齿状数组展平为一维数组。例如:s=[1,2,3]#=>[1,2,3]t=[4,5,6,[7,8]]#=>[4,5,6,[7,8]]a=[s,t,9,10]#=>[[1,2,3],[4,5,6,[7,8]],9,10]a.flatten#=>[1,2,3,4,5,6,7,8,9,10 最佳答案 递归解决方案:IEnumerableFlatten(IEnumerablearray){foreach(variteminarray){if(itemisIEnume
我最近从C#转向了Ruby,我发现自己无法制作可折叠的标记代码区域。我只是想到做这种事情应该没问题:classExamplebegin#agroupofmethodsdefmethod1..enddefmethod2..endenddefmethod3..endend...但是这样做真的可以吗?method1和method2最终与method3是同一种东西吗?还是有一些我还没有见过的用于执行此操作的Ruby惯用语? 最佳答案 正如其他人所说,这不会改变方法定义。但是,如果要标记方法组,为什么不使用Ruby语义来标记它们呢?您可以使用