I'm trying to relocate the position of an external application, i.e. On-Screen Keyboard. It only works correctly if I place a breakpoint. If I run it either from VS without the breakpoint or by running the executable, it doesn't function. Why?
What I have tried:
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
const uint SWP_NOSIZE = 0x0001;
public void SetWindowPosition(string txtAppTitle, string txtWidth, string txtHeight, string txtX, string txtY)
{
IntPtr hWnd = FindWindow(null, txtAppTitle);
if (hWnd != IntPtr.Zero)
{
int x = int.Parse(txtX);
int y = int.Parse(txtY);
SetWindowPos(hWnd, IntPtr.Zero, x, y, 0, 0, SWP_NOSIZE);
}
}
private void btnOnScreenKeyboard_Click(object sender, EventArgs e)
{
SetWindowPosition("On-Screen Keyboard", "0", "0", "155", "545");
}