切换增强指针精度
我们基本上是在创建一个控制面板小程序。 我们需要在鼠标属性中切换“增强指针精度”。
为此,我们需要使用SPI_GETMOUSE
调用SystemParametersInfo
。 它有一个由3个元素组成的数组作为其第三个参数。 我是PInvoke的新手,我尝试了许多签名,但到目前为止还没有运气。 这是我为签名尝试的内容:
[DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool SystemParametersInfo(uint uiAction, uint uiParam, [MarshalAs(UnmanagedType.LPArray)] ref long[] vparam, SPIF fWinIni); static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref long[] vparam, SPIF fWinIni);
以上都没有为我工作,这是我得到的例外:
System.AccessViolationException
:尝试读取或写入受保护的内存。 这通常表明其他内存已损坏。
在搜索时我想出了这个在VB中。
解决方案:感谢GWLlosa的回答 ,我想出了解决方案:
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo", SetLastError = true)] public static extern bool SystemParametersInfoGet(uint action, uint param, IntPtr vparam, SPIF fWinIni); public const UInt32 SPI_GETMOUSE = 0x0003; [DllImport("user32.dll", EntryPoint = "SystemParametersInfo", SetLastError = true)] public static extern bool SystemParametersInfoSet(uint action, uint param, IntPtr vparam, SPIF fWinIni); public const UInt32 SPI_SETMOUSE = 0x0004; public static bool ToggleEnhancePointerPrecision(bool b) { int[] mouseParams = new int[3]; // Get the current values. SystemParametersInfoGet(SPI_GETMOUSE, 0, GCHandle.Alloc(mouseParams, GCHandleType.Pinned).AddrOfPinnedObject(), 0); // Modify the acceleration value as directed. mouseParams[2] = b ? 1 : 0; // Update the system setting. return SystemParametersInfoSet(SPI_SETMOUSE, 0, GCHandle.Alloc(mouseParams, GCHandleType.Pinned).AddrOfPinnedObject(), SPIF.SPIF_SENDCHANGE); }
此文档也certificate是有用的。
你有没有尝试过:
[DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool SystemParametersInfo(SPI uiAction, uint uiParam, IntPtr pvParam, SPIF fWinIni);
无耻地解除了:
https://www.pinvoke.net/default.aspx/user32/SystemParametersInfo.html
上述就是C#学习教程:切换增强指针精度分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1030296.html