private bool EnumChildWindowsCallback(IntPtr handle, IntPtr lparam)
        {
            StringBuilder className = new StringBuilder(100);
            GetClassName(handle, className, className.Capacity);
            MessageBox.Show(className.ToString());
            
            string cn = className.ToString();
            if (className.ToString() == "MacromediaFlashPlayerActiveX")
            {
                Point point = GetFlashPointFromHandle(handle);
                if (point.X == ((webBrowser1.Document.DomDocument) as HTMLDocument).getElementById("obj1").offsetLeft && point.Y == ((webBrowser1.Document.DomDocument) as HTMLDocument).getElementById("obj1").offsetTop)
                {
                    webBrowser1.Document.Body.ScrollTop = point.Y;
                    int x = Convert.ToInt32(textBox1.Text); // X coordinate of the click
                    int y = Convert.ToInt32(textBox2.Text); // Y coordinate of the click
                    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
                }
            }
            return true;
        }
EnumChildWindows(webBrowser1.Handle, new EnumChildrenCallback(EnumChildWindowsCallback), IntPtr.Zero);//调用网页中的flash插件如果是设计的时候插进去的元素,而可以取出来MacromediaFlashPlayerActiveX
如果flash的object元素是用javascript动态产生的,用spy++查看那就没有flash句柄了,以上函数也取不出来实在不行,我就想得到flash相对于屏幕的坐标,然后设置鼠标位置并模拟单击,这个怎么实现

解决方案 »

  1.   

    1.取Flash对象以及其坐标,最好是通过Dom接口。如何操作WebBrowser中的DOM你另外查一下。
    2.标识Flash对象,最好是直接用Flash的ID,不要使用类。因为如何有多个FLASH你怎么办?(如果没有指定ID,向开发提一下需求)
    3.获取FLASH对象的坐标,也可以通过在WebBrowser中执行JS函数:getBoundingClientRect
    4.注意:取屏幕绝对坐标是元素坐标与BROWSER客户区域绝对坐标运算得到。
    5.点击操作是:通过/65535换算后,使用Mouse_event实现。
      

  2.   

    webbrowser中获取网页元素我会((webBrowser1.Document.DomDocument) as HTMLDocument).getElementById("obj1")
    这里的obj1就是flash的id
    可这获取的元素不能转成flash元素,又不能实现单击
      

  3.   

    刚才我已经能够计算出flash的屏幕坐标,并且可以实现设置鼠标位置并单击
    但是为什么javascript动态产生的flash元素<object></object>用spy++就没有句柄呢