I have my application in C # , I need to fill in three fields in another application, I'm using this code to pick up the other application and send sendkeys
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string className, string windowTitle);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, ShowWindowEnum flags);
[DllImport("user32.dll")]
private static extern int SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowPlacement(IntPtr hWnd, ref Windowplacement lpwndpl);
private enum ShowWindowEnum
{
Hide = 0,
ShowNormal = 1, ShowMinimized = 2, ShowMaximized = 3,
Maximize = 3, ShowNormalNoActivate = 4, Show = 5,
Minimize = 6, ShowMinNoActivate = 7, ShowNoActivate = 8,
Restore = 9, ShowDefault = 10, ForceMinimized = 11
};
private struct Windowplacement
{
public int length;
public int flags;
public int showCmd;
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition;
}
public void TraerVentanaAlFrente(string proceso)
{
IntPtr wdwIntPtr = FindWindow(null, proceso);
//Obtener el hWnd del proceso
Windowplacement placement = new Windowplacement();
GetWindowPlacement(wdwIntPtr, ref placement);
// Verificar si la ventana esta minimizada
if (placement.showCmd == 2)
{
//Si la ventana esta minimizada restaurarla
ShowWindow(wdwIntPtr, ShowWindowEnum.Restore);
}
//Hacer foco en la ventana
SetForegroundWindow(wdwIntPtr);
}
This part works well, with the code you can lift and do focus in the other application, the problem is that the other application has two different windows, and always makes me focus in window 1 and I need you to focus on window 2