日期:2014-05-20  浏览次数:21683 次

【API求教】C#根据flash句柄获取网页内flash的对象
根据句柄获取网页内flash的对象
首先我已经获取了flash的句柄,通过webbrowser插件

结构如下:webHandle:1900946
Handle:2031998|windowsname:|classname:Shell Embedding
Handle:2097774|windowsname:|classname:Shell DocObject View
Handle:3408466|windowsname:|classname:Internet Explorer_Server
Handle:1245802|windowsname:|classname:MacromediaFlashPlayerActiveX

网上有人实现了 不过是VB的代码  我调用api后老是错误。http://hi.baidu.com/%C4%BE%D2%D7%D8%A3/blog/item/9e12eb61cbc090c18db10dc8.html

AccessibleObjectFromWindow(phwnd, (uint)OBJID.CLIENT, ref guid, ref flash_main);获取的flash对象为空的、、

代码如下:

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;
using Accessibility;


namespace webgame
{
    public partial class mian : Form
    {
        public mian()
        {
            InitializeComponent();
        }
        //①dll导入
        //FindWindow
        [DllImport("user32.dll")]
        public static extern int FindWindow(string className, string title);
        //FindWindowEx
        [DllImport("user32.dll")]
        public static extern int FindWindowEx(int parent, int next, string ClassName, string title);
        //SetWindowText
        [DllImport("user32")]
        public static extern int SetWindowText(int handle, string title);
        //GetWindowText
        [DllImport("user32.dll")]
        private static extern int GetWindowText(int hWnd, StringBuilder title, int size);
        //GetClassName
        [DllImport("user32.dll")]
        private static extern int GetClassName(int hWnd, StringBuilder lpClassName, int nMaxCount);
        //SendMessage
        [DllImport("User32.dll")]
        private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
        //EnumWindows  需回调
        [DllImport("user32.dll")]
        //public static extern int EnumWindows(EnumWindowsProc lpfn, int lParam);
        public static extern int EnumWindows(CallBack lpfn, int lParam);
        //EnumChildWindows  需回调
        [DllImport("user32.dll")]
        public static extern int EnumChildWindows(int Parenthandle, CallBack lpfn, int lParam);
        //获取窗口标题
        [DllImport("user32", SetLastError = true)]
        public static extern int GetWindowText(
        IntPtr hWnd, //窗口句柄
        StringBuilder lpString, //标题
        int nMaxCount  //最大值
        );
        //根据坐标获取窗口句柄
        [DllImport("user32")]
        private static extern IntPtr WindowFromPoint(
        Point Point  //坐标
        );
        //获取pid根据handle
        [DllImport("user32", EntryPoint = "GetWindowThreadProcessId")]
        private static extern int GetWindowThreadProcessId(int hwnd, out int pid);
        //根据handle获取对象
        [DllImport("atl.dll")]
        private static extern int AtlAxGetControl(int hwnd,ref Object obj);
        //获取对象