About the use of the MFC WebBrowser plug-in

Source: Internet
Author: User

Recently wrote things often need to embed some browsers, Microsoft provides a better interface, can be embedded in MFC program in a simple browser, is the form of an ActiveX plug-in to provide the interface, the use of more convenient, here I will simply record the use of this plugin

Here I use VC6 for example, my machine is too rotten to run vs this giant-level software.

First, create a dialog box and right-click on the plugin to insert ActiveX into the dialog.


You can see that Microsoft offers a lot of ActiveX plugins for us to choose from.


When the browser plugin is selected to be able to see a browser's ActiveX plugin, let's associate a variable m_test


When you are connected, fill in a message response at the OK button.

M_test. Navigate ("www.baidu.com", null,null,null,null);

Use a member function of this variable to open this URL





A few questions about WebBrowser

1. about how to get the content of this page

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;//Stores HTML source code CComBSTR html_t;//used to convert a BSTR to a string pbody->get_innerhtml (&html) that cout can handle; CString Strcookie (HTML); CFile myfile ("1.html", cfile::modewrite| cfile::modecreate); myfile. Write (Strcookie,strcookie.getlength ()); myfile. Close ();p body->release ();        Lpdocument2->release ();    }    Lpdispatch->release ();

2. There is a cookie about how to get this page

    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, "current Cookie", mb_iconinformation);  } Lpdocument2->put_cookie (NULL);p body->release ();        Lpdocument2->release ();    }    Lpdispatch->release ();

3. About some message mappings

Often we have to wait for the page to load to do some work, Microsoft provides us with a rich message map, in the ClassWizard can see


Write it here, and use it to study it.

Rookie speech, for entertainment only!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.