winform项目 在form1里面放一个webbrowser控件  3个textbox控件 1个button 1个timer控件然后代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace 学习项目
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //API
        [DllImport("user32")]
        private static extern IntPtr WindowFromPoint(int X, int Y);        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Interval = 100;
            timer1.Start();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            textBox1.Text = WindowFromPoint(Cursor.Position.X, Cursor.Position.Y).ToString();
        }        private void button1_Click(object sender, EventArgs e)
        {
            textBox2.Text = webBrowser1.Handle.ToString();
        }
    }
}
问题:为什么通过把鼠标移动到webbrowser那里 显示的句柄和 webBrowser1.Handle 的句柄不一样?   
如何取webbrowser的句柄?

解决方案 »

  1.   

    webBrowser1.Handle,这不就是webbrowser的句柄吗,还要怎么取,webBrowser1页面上的组件有各自的句柄,不能和webBrowser1混为一谈
      

  2.   

    补充一下问题: 为什么我痛过 API函数 WindowFromPoint 取得的句柄和webBrowser1.Handle 取得的句柄不一样?
      

  3.   

    webBrowser1是C#里比较特殊的一个控件。它仅仅是一个框架而已,真正承载网页内容的是navigater后IE内核所生成的Internet Explorer_Server窗口(用SPY++可看到)。原有的webBrowser框架被Internet Explorer_Server所遮盖。
    如果要获取Internet Explorer_Server窗口句柄,建议使用该贴中方法:
    http://topic.csdn.net/u/20110613/19/feb74217-62bc-4560-89ae-d760266c4d85.html