在杀死 TabletKeyboard(TabTip.exe) 应用程序的进程后,wpf 中的应用程序不会恢复到其原始大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16601424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:48:57  来源:igfitidea点击:

After killing the process for TabletKeyboard(TabTip.exe) application doesn't bring back to its original size in wpf

c#wpfwindows-8resizewindow

提问by Abin Davis

I have a wpf application which runs on the windows 8 tablet . And in order to bring the keyboard for typing when the focus is on any TextBox.

我有一个在 windows 8 平板电脑上运行的 wpf 应用程序。并且为了在打字时带上键盘,重点放在任何TextBox.

I am invoking the process TabTip.exe to show the keyboard, and when the keyboard is shown my application shrinks. And after all manipulation, there is a save button. When I click on the save button, the keyboard should disappear and my application should come back to its original size.

我正在调用进程 TabTip.exe 来显示键盘,当显示键盘时,我的应用程序会缩小。并且在所有操作之后,还有一个保存按钮。当我点击保存按钮时,键盘应该消失,我的应用程序应该恢复到原来的大小。

I am killing the process TabTip.exe to close the keyboard, but the application will not get re-sized to its original size .

我正在终止进程 TabTip.exe 以关闭键盘,但应用程序不会重新调整到其原始大小。

I tried:

我试过:

if (process.ProcessName == "TabTip")
{
    Application.Current.MainWindow.VerticalAlignment = VerticalAlignment.Stretch;
    process.Kill();
    Application.Current.MainWindow.Height = SystemParameters.WorkArea.Height;
    Application.Current.MainWindow.Width = SystemParameters.WorkArea.Width;
    Application.Current.MainWindow.WindowState = WindowState.Normal;
    Application.Current.MainWindow.WindowState = WindowState.Maximized;
    break;
} 

Does anybody knows to restore the application to its original size after killing the TabTip.exe?

有人知道在杀死 TabTip.exe 后将应用程序恢复到原始大小吗?

回答by Elliot Swart

The Windows 8 keyboard has a number of rendering problems. These can be mitigated by starting the keyboard in its smaller mode (equivalent to hitting the minimize button). It plays much better with WPF then, actually minimizing and expanding when the process is launched and closed.

Windows 8 键盘有许多呈现问题。这些可以通过以较小的模式启动键盘(相当于点击最小化按钮)来缓解。它与 WPF 一起玩得更好,实际上在启动和关闭进程时最小化和扩展。

This requires launching the process in this mode, and closing it in a nicer way than you are doing right now

这需要以这种模式启动进程,并以比现在更好的方式关闭它

Include these libraries:

包括这些库:

using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Interop;

And define this external functions:

并定义这个外部函数:

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool PostMessage(int hWnd, uint Msg, int wParam, int lParam);

[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String sClassName, String sAppName);

Open the keyboard with:

打开键盘:

public static void openKeyboard()
    {
        ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
        myProcess = Process.Start(startInfo);
    }

and close it with:

并关闭它:

public static void closeKeyboard()
    {
        uint WM_SYSCOMMAND = 274;
        uint SC_CLOSE = 61536;
        IntPtr KeyboardWnd = FindWindow("IPTip_Main_Window", null);
        PostMessage(KeyboardWnd.ToInt32(), WM_SYSCOMMAND, (int)SC_CLOSE, 0);
    }

This will give you the best behaved windows 8 on screen keyboard you can get. With any luck it will fix your rendering issues.

这将为您提供屏幕键盘上表现最佳的 Windows 8。运气好的话,它将解决您的渲染问题。

回答by Barrie

Abin - you asked about closing the keyboard window rather than killing the process. That's what I'm doing in a WPF app and by closing the window, my main application's window will resize as expected. A quick console app to demonstrate hiding the keyboard is here (note that this assumes you're using the keyboard in docked mode rather than the floating minimal mode):

Abin - 你问的是关闭键盘窗口而不是终止进程。这就是我在 WPF 应用程序中所做的,通过关闭窗口,我的主应用程序的窗口将按预期调整大小。演示隐藏键盘的快速控制台应用程序在这里(请注意,这假设您在停靠模式而不是浮动最小模式下使用键盘):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace TabTipTest
{
    class Program
    {
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(String sClassName, String sAppName);

        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

        /// <summary>
        /// The command for a user choosing a command from the Window menu (see http://msdn.microsoft.com/en-gb/library/windows/desktop/ms646360(v=vs.85).aspx).
        /// </summary>
        public const int WM_SYSCOMMAND = 0x0112;

        /// <summary>
        /// Closes the window.
        /// </summary>
        public const int SC_CLOSE = 0xF060;

        static void Main(string[] args)
        {
            HideKeyboard();
        }

        /// <summary>
        /// Gets the window handler for the virtual keyboard.
        /// </summary>
        /// <returns>The handle.</returns>
        public static IntPtr GetKeyboardWindowHandle()
        {
            return FindWindow("IPTip_Main_Window", null);
        }

        /// <summary>
        /// Hides the keyboard by sending the window the close command.
        /// </summary>
        public static void HideKeyboard()
        {
            IntPtr keyboardHandle = GetKeyboardWindowHandle();

            if (keyboardHandle != IntPtr.Zero)
            {
                SendMessage(keyboardHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
            }
        }
    }
}