请教各位大侠一个关于向webbrowser发送鼠标单击消息的问题

GGYYBOY 2012-05-01 11:52:43

各位大虾,下面是我的C#代码,我想向webBrowser的某一个位置发送一个鼠标单击消息,但是我用了所有的办法,用SPY++检测都没法看到鼠标点击消息
怎样才能像webbrowser的指定位置发鼠标单击消息,各位大虾能否给些指教,十分感谢。

const int WM_LBUTTONDOWN = 0x0201; //定义了鼠标的左键点击消息
const int WM_LBUTTONUP = 0x0202;//定义了鼠标的左键点击消息
const int WM_CLICK = 0x00F5;
const int WM_SETFOCUS = 0x0007;
const int WM_MOUSEMOVE = 0x0200;
Point p = new Point(web.Location.X+10,web.Location.Y+10);

IntPtr i = (IntPtr)(25 <<16) + 50;
SendMessage(this.ccwebBrowser.Handle, WM_MOUSEMOVE, (IntPtr)0, i);
Thread.Sleep(500);
SendMessage(this.ccwebBrowser.Handle, WM_SETFOCUS, (IntPtr)0, (IntPtr)0);
SendMessage(this.ccwebBrowser.Handle, WM_CLICK, (IntPtr)0, i);
SendMessage(this.ccwebBrowser.Handle, WM_LBUTTONDOWN, (IntPtr)0, i);
SendMessage(this.ccwebBrowser.Handle, WM_LBUTTONUP, (IntPtr)0, i);
...全文
303 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xtfnpgy 2014-10-17
  • 打赏
  • 举报
回复
学习学习
GGYYBOY 2012-05-02
  • 打赏
  • 举报
回复
webbrowser和Internet Explorer_Server到底是一种什么关系啊
bdmh 2012-05-02
  • 打赏
  • 举报
回复
其实你不是给webbrowser发消息,而是给他内部嵌入的document窗体发消息,你通过spy++可以看到窗口层次
  • 打赏
  • 举报
回复
我其实对这东西也不很懂,靠看spy++的信息及google出来的结果,多次调试出来的。
GGYYBOY 2012-05-02
  • 打赏
  • 举报
回复
感谢楼上大虾 一大早把他测试了 完全正确

可是为什么用this.ccwebBrowser.Handle就不行 一定要用handle = FindWindowEx(handle, IntPtr.Zero, "Internet Explorer_Server", null);呢 webbrowser不是一个控件吗 每个控件有他的句柄 原理上似乎也没错
楼上的大虾能否给点提示 我也好自己去找相关资料了解下

非常感谢
  • 打赏
  • 举报
回复
你没有取到正确的句柄,应该是:

IntPtr handle = webBrowser1.Handle;
handle = GetWindow(handle, 5);
handle = FindWindowEx(handle, IntPtr.Zero, "Shell DocObject View", null);
handle = FindWindowEx(handle, IntPtr.Zero, "Internet Explorer_Server", null);
这样拿到的才是正确的句柄。用这个handle去发消息,spy++就能捕捉到。测试通过。

FindWindowEx的P/Invoke签名:
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2);

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧