鼠标模拟点击webBrowser中元素的坐标


using System;

2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Text; 7 using System.Windows.Forms; 8 using System.Runtime.InteropServices; 9 10 namespace BrowserMouseClick 11 { 12 public partial class Form1 : Form 13 { 14 [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] 15 static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); 16 17 [DllImport("user32.dll", SetLastError = true)] 18 static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd); 19 20 [DllImport("user32.dll", CharSet = CharSet.Auto)] 21 static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); 22 23 public Form1() 24 { 25 InitializeComponent(); 26 } 27 28 private void Form1_Load(object sender, EventArgs e) 29 { 30 webBrowser1.Navigate("http://www.devpub.com"); 31 } 32 33 private void btnMouseClick_Click(object sender, EventArgs e) 34 { 35 int x = 100; // X coordinate of the click 36 int y = 80; // Y coordinate of the click 37 IntPtr handle = webBrowser1.Handle; 38 StringBuilder className = new StringBuilder(100); 39 while (className.ToString() != "Internet Explorer_Server") // The class control for the browser 40 { 41 handle = GetWindow(handle, 5); // Get a handle to the child window 42 GetClassName(handle, className, className.Capacity); 43 } 44 45 IntPtr lParam = (IntPtr)((y << 16) | x); // The coordinates 46 IntPtr wParam = IntPtr.Zero; // Additional parameters for the click (e.g. Ctrl) 47 const uint downCode = 0x201; // Left click down code 48 const uint upCode = 0x202; // Left click up code 49 SendMessage(handle, downCode, wParam, lParam); // Mouse button down 50 SendMessage(handle, upCode, wParam, lParam); // Mouse button up 51 } 52 } 53 } 优质内容筛选与推荐>>
1、.NET技术-.NET理论资料-Amoskeag coding rules
2、扩展kmp模板
3、BZOJ 4650: [Noi2016]优秀的拆分
4、洛谷 P2251 质量检测(st表)
5、websocket


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号