使用 C# 中的 SystemParametersInfo (SPI_GETSCREENREADER SPI_SETSCREENREADER)
我这样做正确吗?
[DllImport("user32", CharSet = CharSet.Auto)]
internal static extern long SystemParametersInfo(long uAction, int lpvParam, ref bool uParam, int fuWinIni);
...
public static bool IsScreenReaderRunning()
{
long SPI_GETSCREENREADER = 70L;
bool bScreenReader = false;
long retVal;
retVal = SystemParametersInfo(SPI_GETSCREENREADER, 0, ref bScreenReader, 0);
//uint iParam = 0;
//uint iUpdate = 0;
//bool result = false;
//bool bReturn = SystemParametersInfo(SPI_GETSCREENREADER, iParam, &bScreenReader, iUpdate);
return bScreenReader;
}
public static void ScreenReaderOn()
{
long SPI_GETSCREENREADER = 71L;
bool bScreenReader = true;
long retVal;
retVal = SystemParametersInfo(SPI_GETSCREENREADER, 0, ref bScreenReader, 0);
}
public static void ScreenReaderOff()
{
long SPI_GETSCREENREADER = 71L;
bool bScreenReader = false;
long retVal;
retVal = SystemParametersInfo(SPI_GETSCREENREADER, 0, ref bScreenReader, 0);
}
Am I doing this correctly?
[DllImport("user32", CharSet = CharSet.Auto)]
internal static extern long SystemParametersInfo(long uAction, int lpvParam, ref bool uParam, int fuWinIni);
...
public static bool IsScreenReaderRunning()
{
long SPI_GETSCREENREADER = 70L;
bool bScreenReader = false;
long retVal;
retVal = SystemParametersInfo(SPI_GETSCREENREADER, 0, ref bScreenReader, 0);
//uint iParam = 0;
//uint iUpdate = 0;
//bool result = false;
//bool bReturn = SystemParametersInfo(SPI_GETSCREENREADER, iParam, &bScreenReader, iUpdate);
return bScreenReader;
}
public static void ScreenReaderOn()
{
long SPI_GETSCREENREADER = 71L;
bool bScreenReader = true;
long retVal;
retVal = SystemParametersInfo(SPI_GETSCREENREADER, 0, ref bScreenReader, 0);
}
public static void ScreenReaderOff()
{
long SPI_GETSCREENREADER = 71L;
bool bScreenReader = false;
long retVal;
retVal = SystemParametersInfo(SPI_GETSCREENREADER, 0, ref bScreenReader, 0);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
pinvoke声明完全错误,它是从VB6代码复制的。返回类型和参数不是 long(VB6 int32 类型),它们是 int。 Pinvoke.net 是一个获得良好声明的不错网站。
当您得到错误返回时,不要忘记抛出 Win32Exception,这样失败就不会消失。
The pinvoke declaration is completely wrong, it was copied from VB6 code. The return type and arguments are not long (the VB6 int32 type), they are int. Pinvoke.net is a decent site to get good declarations.
Don't forget to throw Win32Exception when you get a false return so failure isn't silent.
根据这篇文章,SystemParametersInfo 的最后一个参数应该是:
更改值时。
Based on this article, the last parameter to SystemParametersInfo should be:
When changing the value.