Travel the world

Climb the mountains

Post Page Advertisement [Top]

Click at certain coordinate of specific window - C# Automation

Click at certain coordinate of specific window - C# Automation


At previous post, we could click  at certain coordinate on screen. Today, we do abit more complicated - Click at certain coordinate of specific window.

To do that, we have to find ID Process of that window by find its handle (identification of each window)

We can find handle by several ways:
1)
            var handl = Process.GetProcessById(ID Process);
and then its handle:
            var handl = Process.GetProcessById(ID Process).MainWindowHandle;
2) Use AutoControl in Kautohelper.dll
 IntPtr hWnd = IntPtr.Zero;
 hWnd = AutoControl.FindWindowHandle()
public static IntPtr FindWindowHandle(string className, string windowName);
 className get by use Autoit Window Info or Spyxx

After we got handle,
            var pointToClick = AutoControl.GetGlobalPoint(hWnd, x, y);

x, y represent coordinate of point needed to click in comparision with window.

x, y get by use Autoit Window Info (coordinate of control compared with window)

pointToClick here return a Point() which represent coodinate of point needed to click in comparision with screen.

Befor click, we need to Focus on that window

            AutoControl.BringToFront(hWnd);
Finally,
AutoControl.MouseClick(pointToClick, mouseKey);

Không có nhận xét nào:

Đăng nhận xét

Bottom Ad [Post Page]