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!