And so you need to get the coordinates of the window of the running application.
using System; using System.Diagnostics; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Program { [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetWindowRect(HandleRef 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 public override string ToString() { return string.Format("{0,4} {1,4} {2,4} {3,4}", Left, Top, Right, Bottom); } } static void Main(string[] args) { var proc = Process.GetProcessesByName("Notepad++"); RECT rct; if (!GetWindowRect(new HandleRef(null, proc[0].MainWindowHandle), out rct)) { Console.WriteLine("ERROR"); return; } Console.WriteLine(rct.ToString()); Console.ReadKey(); } } }
Next, in the same way, we get the coordinates of the message box and the child of the button, that's all.