【发布时间】:2014-04-02 10:53:46
【问题描述】:
我正在开发 dekstop 应用程序,它将在 Windows 平板电脑(C#)上使用,并且在某些时候想知道 TabTip.exe 屏幕键盘是否可见。问题是,当我在运行 Win 8.1 的计算机和运行 Win 8.1 的平板电脑上测试它时,行为是不同的。我将从我的测试应用程序中复制小的代码部分。
我要做的是使用 user32.dll 来找出答案
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String sClassName, String sAppName);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool IsWindowVisible(IntPtr hWnd);
我的示例应用程序中有一个按钮,当我按下按钮时,它会打印出 TabTip 是否可见
public void IsVisible(object sender, RoutedEventArgs e)
{
IntPtr KeyboardWnd = FindWindow("IPTip_Main_Window", null);
Console.WriteLine("Keyboard is visible :" + IsWindowVisible(KeyboardWnd));
}
问题是...当我在运行 Windows 8.1 的计算机上启动它时,我从 IsWindowVisible 获得了正确的值。
在平板电脑上...我总是很真实。有人知道为什么吗?
更新
我尝试使用建议的 GetWindowRect。这与 isWindowVisible 相同。在平板电脑上,无论是否看到键盘,GetWindowRect 都返回 TRUE。值 上、下、左、右 aleays 具有价值。在常规计算机上,当 TabTip 不可见时,GetWindowRect 返回 FALSE。谁能解释我如何检测 TabTip 在 TABLET 上是否可见(在当前窗口中可见)?
【问题讨论】:
-
实际上
IsWindowVisible只是检查标志 WS_VISIBLE。尝试使用GetWindowRect、GetWindowLong。可能有一个线索,比如:窗口实际上并没有隐藏,只是在你看不到它的地方移动...... -
错误检查不充分。 IsWindowVisible(null) 将返回一个猜测,因为 NULL 窗口句柄可以替代桌面窗口。
-
GetWindowRect 似乎与 IsWindowVisible 一样可用。我可以在运行在 8.1 上但不能在平板电脑上运行的计算机上检测到它,例如 GetWindowRect 返回 TRUE、Top、bottom 在平板电脑上总是有值(不是 0)...似乎平板电脑无法识别关闭(隐藏?) TabTip 的事件。任何人都知道我如何在平板电脑上检测到 TabTip 是否可见?
标签: c# windows-8.1 tablet .net-4.5