110,534
社区成员
发帖
与我相关
我的任务
分享
void SendMouseClick(int PointX, int PointY)
{
if(this.webBrowser1.InvokeRequired)
{
SendMouseCallback sendMouseCallback = new SendMouseCallback(SendMouseClick);
this.webBrowser1.Invoke(sendMouseCallback, PointX, PointY);
}
else
{
IntPtr handle = this.webBrowser1.Handle;
StringBuilder className = new StringBuilder(100);
while (className.ToString() != "MacromediaFlashPlayerActiveX") // The class control for the browser
{
handle = GetWindow(handle, 5); // Get a handle to the child window
GetClassName(handle, className, className.Capacity);
}
IntPtr lParam = (IntPtr)((PointY << 16) | PointX); // The coordinates
IntPtr wParam = IntPtr.Zero; // Additional parameters for the click (e.g. Ctrl)
const uint downCode = 0x201; // Left click down code
const uint upCode = 0x202; // Left click up code
PostMessage(handle, downCode, wParam, lParam); // Mouse button down
Thread.Sleep(1);
PostMessage(handle, upCode, wParam, lParam); // Mouse button up
Thread.Sleep(200);
SendMessage(handle, downCode, wParam, lParam); // Mouse button down
Thread.Sleep(200);
SendMessage(handle, upCode, wParam, lParam); // Mouse button up
}
}