我有一个要在 Windows 7 平板电脑上运行的应用程序,需要将屏幕键盘停靠在屏幕底部。理想情况下,我想阻止某人移动或更改这些设置。
使用此处发布到堆栈溢出答案的评论如何在 Windows Vista/7 中以编程方式控制文本输入面板 (TabTip.exe)我能够以编程方式将键盘停靠在屏幕底部,这是一个开始。我必须以更高的权限运行才能让它工作
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
string onScreenKeyboardPath = @"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe";
var onScreenKeyboardProc = Process.Start(onScreenKeyboardPath);
IntPtr wKB = FindWindow("IPTip_Main_Window", null);
const uint WM_COMMAND = 0x111;
// Where message is 10021 for dock bottom, 10023 for dock top and 10020 for floating
bool x = PostMessage(wKB, WM_COMMAND, new IntPtr(10021), IntPtr.Zero);
我希望能够比这更好地控制大小,所以我尝试像这样移动窗口:
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
private const uint SWP_SHOWWINDOW = 0x0040;
bool ok = SetWindowPos(wKB, this.Handle, 0, 500, 750, 500, SWP_SHOWWINDOW);
ok 返回 true 但 windows 不让步。如果我尝试使用记事本执行此操作,它会完美运行。那么这个特定程序有问题吗?