阿里旺旺自动回复工具开发<二>

昨天说到获取消息得从Internet Explorer_Server这个里面进行获取。获取这个控件里面的HTML内容是非常方便的,因为在Visual Studio中可以直接在引用中找到Interop.SHDocVw。通过这个可以很方便的将里面的内容获取出来。

获取HTML内容代码:

/**********获取内容的方法***********/
//hwndInterneExplorer_Server:浏览器控件句柄
//document:获取的IHTMLDocument2对象
public static void GetInterfacesByHandleOfInternetExplorer_Server(IntPtr hwndInterneExplorer_Server,
            out IHTMLDocument2 document)
        {
            document = null;

            Guid IID_IWebBrowser2 = typeof(SHDocVw.IWebBrowser2).GUID;
            Guid IID_IHTMLDocument2 = typeof(IHTMLDocument2).GUID;
            Guid SID_SWebBrowserApp = typeof(SHDocVw.IWebBrowserApp).GUID;

            try
            {
                int nMsg = WinApi.RegisterWindowMessage("WM_HTML_GETOBJECT");

                UIntPtr lRes;
                WinApi.SendMessageTimeout(hwndInterneExplorer_Server, nMsg, 0, 0,
                    WinApi.SMTO_ABORTIFHUNG, 1000, out lRes);

                if (!(bool)(lRes.ToUInt32() == 0))
                {
                    int hr = WinApi.ObjectFromLresult((int)lRes.ToUInt32(),
                        ref IID_IHTMLDocument2, 0, out document);

                    if ((document != null))
                    {
                        IntPtr puk = Marshal.GetIUnknownForObject(document);

                        IServiceProvider pro = document as IServiceProvider;

                        object objIWebBrowser2;
                        pro.QueryService(ref SID_SWebBrowserApp, ref IID_IWebBrowser2, out objIWebBrowser2);
                        IWebBrowser2 web = objIWebBrowser2 as IWebBrowser2;
                    }
                }
            }
            catch
            {
            }
        }



/**********IServiceProvider接口类***********/
[
    ComImport, Guid("6d5140c1-7436-11ce-8034-00aa006009fa"),
    InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
    ]
    public interface IServiceProvider
    {
        void QueryService(ref Guid guidService,
            ref Guid riid,
            [MarshalAs(UnmanagedType.Interface)] out object ppvObject);
    }

  通过上面的代码就可以获得消息内容了,离成功又进了一步~~但是问题又来了,里面的HTML内容获取出来之后该怎么分析呢?在2010版本的旺旺中每次聊天消息都会自带上次的内容,所以获取的HTML内容比较麻烦不方便分析。于是看了看设置里面

把上面的勾去掉就可以将聊天框中的历史消息去掉,每次获取的HTML内容就是我们需要的消息内容了。至于怎么处理就不详细写出来了。既然消息已经获取到了,就可以往数据库查了然后获取对应回复。今天的问题又解决了,下一步就是怎么用WinApi点击自绘的发送按钮了。明天继续~~~~~

posted @ 2011-11-30 21:04  likefeng  阅读(1632)  评论(0)    收藏  举报
李科锋