自动完成文本框和[隐藏指针在打字"在Windows [英] AutoComplete textbox and "Hide Pointer While Typing" in windows

查看:139
本文介绍了自动完成文本框和[隐藏指针在打字"在Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何能隐藏指针虽然键入选项,通过应用程序被停用?我在与光标隐藏的问题并没有得到回来没有pressing逃逸或失去窗口焦点。这个应用程序已经用C#编写,并使用WPF。因为它会使用任何技术有可能是一个可能的技术具体的答案是不需要的。

How can the "Hide Pointer While Typing" option be disabled by application? I'm having an issue with the cursor hiding and not getting it back without pressing escape or losing window focus. The application has been written in C# and uses WPF. A technology specific answer is not required because it'll likely be possible using any technology.

下面的情景:用户可以输入一个文本框和一个自动完成列表中显示下面的方框中。一旦用户开始虽然键入,他/她可以不再从下拉是因为没有鼠标光标选择项目。

Here's the scenario: A user can type in a TextBox and an AutoComplete list shows up below the box. Once the user starts typing though, he/she can no longer select an item from the drop down because there is no mouse cursor.

我注意到,Firefox不会有此行为。例如,虽然在URL地址栏中键入鼠标指针永远不会消失。还有其他的地方,所以我知道它必须是有可能我已经看到了这种行为。

I noticed that Firefox does not have this behavior. For example, while typing in a URL in the address bar the mouse cursor never disappears. There are other places I've seen this behavior so I know it must be possible.

任何帮助是极大AP preciated!

Any help is greatly appreciated!

推荐答案

我通过设置断点您在文本框中键入的第一次,WPF读公 SystemParameters.MouseVanish 属性,它调用 SystemParametersInfo(SPI_GETMOUSEVANISH,...)来获得鼠标清漆设置。后续调用 SystemParameters.MouseVanish 使用缓存的值。

I discovered by setting breakpoints that the first time you type in a textbox, WPF reads the public SystemParameters.MouseVanish property which calls SystemParametersInfo(SPI_GETMOUSEVANISH, ...) to get the mouse vanish setting. Subsequent calls to SystemParameters.MouseVanish use the cached value.

两种可能的解决方案:


  1. 访问 SystemParameters.MouseVanish ,然后使用反射来覆盖高速缓存的结果,以便后续调用返回false。

  2. 调用Win32的 SystemParametersInfo(SPI_SETMOUSEVANISH,...)关闭清漆(没有通知),然后访问 SystemParameters.MouseVanish ,然后调用 SystemParametersInfo(SPI_SETMOUSEVANISH,...)设置回先前值(无通知)

  1. Access SystemParameters.MouseVanish, then use reflection to overwrite the cached result so subsequent calls return false.
  2. Call Win32's SystemParametersInfo(SPI_SETMOUSEVANISH, ...) to turn off vanish (with no notify), then access SystemParameters.MouseVanish, then call SystemParametersInfo(SPI_SETMOUSEVANISH, ...) to set it back to its prior value (with no notify)

无论这些可以在任何时候在用户开始在文本框中键入之前进行。

Either of these can be done at any time before the user starts typing in the textbox.

下面是反射的解决方案是什么样子:

Here is how the reflection solution would look:

void LocallyDisableMouseVanish()
{
  if(SystemParameters.MouseVanish)
    foreach(var field in typeof(SystemParameters).GetFields(BindingFlags.NonPublic | BindingFlags.Static)
      if(field.Name.Contains("mouseVanish"))
        field.SetValue(null, false);
}

对于普通的目的做这一次就足够了,但有一个可能性,你的应用程序正在运行,而用户更改设置,这将导致在下次访问重新加载MouseVanish值。如果要防止这种情况,使用HwndSource.AddHook挂钩WM_SETTINGCHANGE和时间表回调重新申请的修补程序:

For ordinary purposes doing this once would be enough, but there is a possibility that the user will change settings while your app is running, which would cause the MouseVanish value to be reloaded on next access. If you want to guard against this, use HwndSource.AddHook to hook WM_SETTINGCHANGE and schedules a callback to re-apply the fix:

const int WM_SETTINGCHANGE = 26;

public void AddSettingChangeHook()
{
  _settingChangeWatcher = new HwndSource(new HwndSourceParameters("WM_SETTINGSCHANGE watcher"));
  _settingChangeWatcher.AddHook((IntPtr hwnd, IntPtr msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
  {
    if((int)msg == WM_SETTINGCHANGE)
      Dispatcher.Invoke(DispatcherPriority.Input, new Action(() =>
      {
        LocallyDisableMousePointerVanish();
      });
  });
}

这篇关于自动完成文本框和[隐藏指针在打字"在Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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