c# 在WebBrowser中用SendMessage模擬鼠標(biāo)點(diǎn)擊
更新時(shí)間:2010年02月06日 14:04:10 作者:
想在WebBrowser控件里面模擬鼠標(biāo)點(diǎn)擊,在百度上找了半天,怎么也找不到,還是google強(qiáng)大,在一個(gè)國(guó)外網(wǎng)站上找到的,代碼比較清楚了,不做說(shuō)明。
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace BrowserMouseClick
{
public partial class Form1 : Form
{
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("http://www.devpub.com");
}
private void btnMouseClick_Click(object sender, EventArgs e)
{
int x = 100; // X coordinate of the click
int y = 80; // Y coordinate of the click
IntPtr handle = webBrowser1.Handle;
StringBuilder className = new StringBuilder(100);
while (className.ToString() != "Internet Explorer_Server") // 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)((y << 16) | x); // 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
SendMessage(handle, downCode, wParam, lParam); // Mouse button down
SendMessage(handle, upCode, wParam, lParam); // Mouse button up
}
}
}
想在WebBrowser控件里面模擬鼠標(biāo)點(diǎn)擊,在百度上找了半天,怎么也找不到,還是google強(qiáng)大,在一個(gè)國(guó)外網(wǎng)站上找到的,代碼比較清楚了,不做說(shuō)明。
您可能感興趣的文章:
- C#模擬Http與Https請(qǐng)求框架類實(shí)例
- C#模擬http 發(fā)送post或get請(qǐng)求的簡(jiǎn)單實(shí)例
- C#采用mouse_event函數(shù)實(shí)現(xiàn)模擬鼠標(biāo)功能
- C#實(shí)現(xiàn)的三種模擬自動(dòng)登錄和提交POST信息的方法
- C# SendInput 模擬鼠標(biāo)操作的實(shí)現(xiàn)方法
- 使用C#發(fā)送Http請(qǐng)求實(shí)現(xiàn)模擬登陸實(shí)例
- C#基于socket模擬http請(qǐng)求的方法
- c#模擬銀行atm機(jī)示例分享
- C#模擬window操作鼠標(biāo)的方法
- C#如何使用Bogus創(chuàng)建模擬數(shù)據(jù)示例代碼
相關(guān)文章
asp.net下實(shí)現(xiàn)URL重寫技術(shù)的代碼
asp.net下實(shí)現(xiàn)URL重寫技術(shù)的代碼...2007-10-10ASP.NET項(xiàng)目開(kāi)發(fā)中日期控件DatePicker如何使用
這篇文章主要為大家詳細(xì)介紹了ASP.NET項(xiàng)目開(kāi)發(fā)中日期控件DatePicker的使用方法,感興趣的小伙伴們可以參考一下2016-04-04ASP.NET?MVC使用Log4Net記錄異常日志并跳轉(zhuǎn)到靜態(tài)頁(yè)
這篇文章介紹了ASP.NET?MVC使用Log4Net記錄異常日志并跳轉(zhuǎn)到靜態(tài)頁(yè)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09ASP.NET實(shí)現(xiàn)根據(jù)URL生成網(wǎng)頁(yè)縮略圖的方法
這篇文章主要介紹了ASP.NET實(shí)現(xiàn)根據(jù)URL生成網(wǎng)頁(yè)縮略圖的方法,結(jié)合實(shí)例較為詳細(xì)的分析了asp.net生成網(wǎng)頁(yè)縮略圖的詳細(xì)實(shí)現(xiàn)技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下2015-11-11基于asp.net下使用jquery實(shí)現(xiàn)ajax的解決方法
本文以最簡(jiǎn)單的方法為新手示范如何使用jquery實(shí)現(xiàn)ajax技術(shù)(所以本文是專為新手所寫,老鳥(niǎo)勿噴,大神此處省略一萬(wàn)字)。至于什么是jquery什么是ajax,自己谷歌去2013-05-05