zoukankan      html  css  js  c++  java
  • 有关于mfc webbrowser插件的使用

    最近写的东西中常常需要嵌入一些浏览器,微软提供了一个比较好的接口,可以在MFC写的程序中嵌入一个简易的浏览器,是以ActiveX插件的形式提供的接口,使用起来也比较的方便,这里我就简单记录下这个插件的使用

    这里我用vc6为例吧,我的机器太烂,跑不动vs这种巨人级别的软件。

    1.首先创建一个对话框,在对话框上右击插入ActiveX的插件

    2.可以看到微软提供了很多ActiveX的插件供我们选择。

    3.选中浏览器插件确定后就能看到一个浏览器的ActiveX的插件了,下面我们为他关联一个变量m_test如下图

    4.关联好后在确定按钮处填写一个消息响应。

    m_test.Navigate("www.baidu.com",NULL,NULL,NULL,NULL);

    用这个变量的一个成员函数打开这个网址

    关于WebBrowser几个问题

    1.关于如何取得这个网页的内容

    HRESULT hr;
        IDispatch* lpDispatch;
        lpDispatch = m_WebBrower.GetDocument();
        IHTMLDocument2* lpDocument2;
        hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (PVOID*)&lpDocument2);
        if ( hr == S_OK )
        {
    		
    		
    		IHTMLElement * pBody;
    		lpDocument2->get_body(&pBody);
    		BSTR html;//存放html源代码
    		CComBSTR html_t;//用于将BSTR转换为cout可以处理的字符串
    		pBody->get_innerHTML(&html);
    		CString strCookie(html);
    		CFile myfile("1.html",CFile::modeWrite|CFile::modeCreate);
    		myfile.Write(strCookie,strCookie.GetLength());
    		myfile.Close();
    		pBody->Release();
            lpDocument2->Release();
        }
        lpDispatch->Release();
    

      

     2.有关于如何取得这个网页的cookie

        HRESULT hr;
        IDispatch* lpDispatch;
        lpDispatch = m_WebBrower.GetDocument();
        IHTMLDocument2* lpDocument2;
        hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (PVOID*)&lpDocument2);
        if ( hr == S_OK )
        {
    		
            hr = lpDocument2->get_cookie(&bstrCookie);
            if ( hr == S_OK )
            {
    		CString strCookie(bstrCookie);
    		CFile myfile("1.txt",CFile::modeWrite|CFile::modeCreate);
    		myfile.Write(strCookie,strCookie.GetLength());
    		myfile.Close();
    		//::MessageBox(NULL, strCookie,"当前Cookie", MB_ICONINFORMATION);
    		
    		  }
    		lpDocument2->put_cookie(NULL);
    		pBody->Release();
            lpDocument2->Release();
        }
        lpDispatch->Release();
    

     3.关于一些消息映射

    往往我们要等待网页加载完成才能进行一些操作,微软为我们提供了丰富的消息映射,在ClassWizard中可以看到

    程序员的基础教程:菜鸟程序员

  • 相关阅读:
    Spring(九)Spring中的两种自动代理
    Spring(八)Spring错题总结
    Spring(七)Spring中的四种增强和顾问
    SourceTree使用git
    Idea集成git
    SpringMVC--AbstractController抽象类限定请求提交
    SpringMVC处理器配置方式
    SpringMVC静态资源无法访问解决方案
    SpringMVC--视图解析器
    HandlerMapping执行流程
  • 原文地址:https://www.cnblogs.com/guohu/p/5525893.html
Copyright © 2011-2022 走看看