当前位置: 移动技术网 > IT编程>开发语言>.net > c# 在WebBrowser中用SendMessage模拟鼠标点击

c# 在WebBrowser中用SendMessage模拟鼠标点击

2017年12月12日  | 移动技术网IT编程  | 我要评论

tokyo hot n0635,乐讯网,单枪匹马造句

复制代码 代码如下:

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控件里面模拟鼠标点击,在百度上找了半天,怎么也找不到,还是google强大,在一个国外网站上找到的,代码比较清楚了,不做说明。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网