I need to use an OnScreenKeyboard Component like Native Windows OSK in my Wpf application. I can call the UI by Process.Start("osk.exe") but the UI appears on top of the main ui window. I want to start the OSK app just bottom of my app. Is this possible with any arguments? -eg process.StartInfo.WindowPosition=xxx- I'd prefer to use it before I create my own Component.
OK. I solved my problem with Win32 SetWindowPos method. Sharing if it might help others. Below code is opening and resizing/positioning the Native OSK.exe. It places the keyboard relative to the mouse position.
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
public static implicit operator Point(POINT point)
{
return new Point(point.X, point.Y);
}
}
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out POINT lpPoint);
public static Point GetCursorPosition()
{
POINT lpPoint;
GetCursorPos(out lpPoint);
//bool success = User32.GetCursorPos(out lpPoint);
// if (!success)
return lpPoint;
}
private void OSKMenuItem_Click(object sender, RoutedEventArgs e)
{
Process osk = new Process();
osk.StartInfo.FileName = "osk.exe";
osk.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
osk.Start();
Task.Delay(1000).ContinueWith((a) => {
Point p = GetCursorPosition();
try
{
IntPtr target_hwnd = FindWindowByCaption(IntPtr.Zero, "On-Screen Keyboard");
if (target_hwnd == IntPtr.Zero)
{
Microsoft.Windows.Controls.MessageBox.Show("Error");
}
SetWindowPos(target_hwnd, IntPtr.Zero, (int)p.X - 200, (int)p.Y, 1300, 600, 0);
}
catch (Exception ex)
{
//throw;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.