2013-05-17 6 views
5

私はWindows 8タブレット上で動作するwpfアプリケーションを持っています。また、フォーカスがあるときにキーボードを入力するためには、TextBoxが必要です。TabletKeyboard(TabTip.exe)のプロセスを終了した後、アプリケーションは元のサイズ(wpf)に戻りません。

TabTip.exeプロセスを呼び出してキーボードを表示しています。キーボードが表示されているときにアプリケーションが縮小します。すべての操作の後、保存ボタンがあります。保存ボタンをクリックするとキーボードが消え、アプリケーションは元のサイズに戻ります。

キーボードを閉じるためにTabTip.exeプロセスを終了していますが、アプリケーションのサイズを元のサイズに戻すことはできません。

私が試した:

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; 
} 

は、誰もがTabTip.exeを殺害した後、元のサイズにアプリケーションを復元するために知っていますか?

+0

(プロセス場合、私は のようにすべてのそれらの事を試してみました。 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; 休憩。 } } –

+0

これは間違いなく、物事をやり遂げる方法と似ています。どうしてあなたは自分でそれを作成したり殺したりしていますか?あなたはそのようなことに気づくべきではありません。 –

+1

プロセスを強制終了せずにキーボードを閉じたり隠したりすることはありません.. !!それらの行動を実行するための他の方法? –

答えて

15

Windows 8キーボードには、さまざまなレンダリングの問題があります。これらは、キーボードをより小さいモードで起動することによって軽減できます(最小化ボタンを押すことに相当)。 WPFを使用すると、プロセスが開始され閉じられたときに実際に最小化され展開されるWPFの方がはるかに優れています。

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

と定義し、この外部関数:

これは、このモードでプロセスを起動すると、あなたが今やっているよりも、よりよい方法でそれを閉じる必要が

は、これらのライブラリを含めます
[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); 

キーボードを開く:

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); 
    } 

し、それを閉じる:

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); 
    } 

これはあなたが得ることができ、画面のキーボードで最高の行儀の窓8を与えるだろう。運があれば、レンダリングの問題が解決されます。

+1

これがあなたの質問に答えるなら、同意してください。 –

0

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); 
      } 
     } 
    } 
} 
関連する問題