鼠标模拟点击webBrowser中元素的坐标
2013-01-10 10:41
405 查看
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 }
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 }
相关文章推荐
- c# 在WebBrowser中用SendMessage模拟鼠标点击
- selenium--unittest定位元素内容为空时模拟鼠标点击的方法
- c# 在WebBrowser中用SendMessage模拟鼠标点击
- WEBBROWSER中模拟鼠标点击(SendMessage/PostMessage)
- Webbrowser中模拟连接点击(非鼠标模拟)
- js 获取元素坐标 和鼠标点击坐标
- selenium--unittest定位元素内容为空时模拟鼠标点击的方法
- Webbrowser中模拟连接点击(非鼠标模拟)
- Webbrowser中模拟连接点击(非鼠标模拟)
- Webbrowser中模拟连接点击(非鼠标模拟)
- Webbrowser中模拟连接点击(非鼠标模拟)
- js获取鼠标点击坐标
- js获取鼠标点击时坐标
- pageX、pageY及父元素的页面坐标使提示框跟随鼠标移动
- 模拟鼠标点击和移动
- JavaScript 获取鼠标点击位置坐标
- 如何使用SendMessage函数实现模拟鼠标点击按钮事件?
- C# ,webBrowser,登录,数据填充,模拟点击链接,运行JS函数
- JavaScript 获取鼠标点击位置坐标
- 利用 SHDocVw::IShellWindowsPtr m_spSHWinds 遍历所有IE浏览器,得到里面的所有元素 还有一个是查找IE窗口里的submit按钮,模拟点击