TabTip键盘c#的设置位置不起作用
我试图重新定位TabTib键盘而没有成功SetWindowPos函数返回“True”,但键盘没有移动。 我在Windows 7上使用C#。
`[DllImport(“user32.dll”)] public static extern bool ShowWindow(IntPtr hWnd,int nCmdShow);
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string ClassName, string WindowName);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
Rectangle KeyboardRect;
IntPtr TabTipHandle;
IntPtr GetWindowHandle()
{
return FindWindow("IPTip_Main_Window",null);
}
bool MoveKeyBoard(IntPtr hWnd, int ToX, int ToY)
{
return SetWindowPos(hWnd, this.Handle, ToX, ToY, KeyboardRect.Width, KeyaboardRect.Height, 0x0045);
}
void StartKeyboard()
{
Process.Start(@"C:Program FilesCommon FilesMicrosoft SharedinkTabTip.exe");
TabTipHandle = GetWindowHandle();
KeyboardRect = GetKeyboardRect(TabTipHandle);
textBox1.Text = KeyaboardRect.Top.ToString() + ", " + KeyboardRect .Left.ToString() + ", " + KeyboardRect .Width.ToString() + ", " + KeyboardRect .Height.ToString();
MoveKeyBoard(TabTipHandle, 100, 100);
KeyboardRect = GetKeyboardRect(TabTipHandle);
textBox2.Text = KeyaboardRect.Top.ToString() + ", " + KeyboardRect .Left.ToString() + ", " + KeyboardRect .Width.ToString() + ", " + KeyboardRect .Height.ToString();
}
void button1_Click(object sender, EventArgs e)
{
StartKeyboard();
}
void button2_Click(object sender, EventArgs e)
{
MoveKeyBoard(TabTipHandle, 200, 100);
KeyboardRect = GetKeyboardRect(TabTipHandle);
textBox2.Text = KeyboardRect .Top.ToString() + ", " + KeyboardRect .Left.ToString() + ", " + KeyboardRect .Width.ToString() + ", " + KeyboardRect .Height.ToString();
}
`
如果你在创建这样的过程之后放置一个小的延迟,它将起作用:
Process.Start(@"C:Program FilesCommon FilesMicrosoft SharedinkTabTip.exe");
await Task.Delay(150); // Just a tiny delay before continuing
...
MoveKeyBoard(TabTipHandle, 100, 100);
...
但是现在我正面临一个奇怪的问题,那就是键盘不能完全放置在我希望使用SetWindowPos
。 该窗口似乎摆动的点,直到它保持固定几次调用SetWindowPos
。 很奇怪,如果你会问我。 在缺少任何文档的情况下,我搜索了注册表,因为我注意到TabTip.exe将从与关机完全相同的位置开始。 所以我找到了这两个DWORD注册表值:
HKCUSOFTWAREMicrosoftTabletTip1.7OptimizedKeyboardRelativeXPositionOnScreen
HKCUSOFTWAREMicrosoftTabletTip1.7OptimizedKeyboardRelativeYPositionOnScreen
我对这些值进行了实验,看起来在开始过程之前将两者都设置为50000
将使键盘的左上角位于屏幕的中心。 将两者都设置为0
会将其精确定位在左上角,而100000
则意味着相应地右上角。
上一篇: Set position of TabTip keyboard c# is not working
下一篇: Why Are AsObservable and AsEnumerable Implemented Differently?