I had this problem:

There is an application, from time to time there appears a sign with a choice of the "yes / no" type.

It is necessary to press "yes". I tried to direct the button, take the coordinates of the cursor. But! You need to make the type of protection against the screen resolution, because the same coordinates at different resolutions are located in different places.

So, I think just take the position of the cursor in the window. How to do it?

PS If you know, please tell me, maybe there are some other ways to solve the problem?

1 answer 1

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.