Environment: VS2013
New Project: Dialog box based
① Adding Controls to the dialog box Microsoft Web Browser (Note: The name of the control on VS2013 is Microsoft Web Browser, other compiler amounts are not known)
② Header function:
#include <afxinet.h>
② set the environment variable for the added control (I set the environment variable to M_SA here)
③ set the page you want to open in OnInitDialog ()
M_sa. Navigate ("http://www.baidu.com", NULL, NULL, NULL, NULL);
Do this when a Web page can be displayed, but you will find that there are a lot of problems for us to solve
④ Problem One: Open the Web page is also open, but then click on one of the news, will be braking back to IE browser.
Workaround: At this point we need to add a message function (NEWWINDOW3) to prevent it from jumping to ie.
(Open the Class Wizard, under Command object ID (B): Find the ID number of the control you added, and then find the right message (S): NEWWINDOW3 message function found)
void Cmfcapplication1dlg::onnewwindow3explorer1 (lpdispatch* ppdisp, bool* Cancel, unsigned long dwFlags, LPCTSTR Bstrurlcontext, LPCTSTR bstrURL) {//TODO: Add the message handler code here/*// only in one dialog box to manipulate the page *cancel = TRUE; CString Strurl;strurl = bstrURL; VARIANT Vinfo; VariantInit (&vinfo); This->m_sa. Navigate (strURL, &vinfo, &vinfo, &vinfo, &vinfo); This->showwindow (sw_show); *///*************************************** two methods required ******************************** Web page operation in multiple dialog boxes *cancel = TRUE; CString Strurl;strurl = bstrurl;//New dialog box cmfcapplication1dlg *pnewdlg = new Cmfcapplication1dlg;pnewdlg->create (Idd_mfcapplication1_dialog, this);p Newdlg->showwindow (sw_show);//Web Navigation, New dialog box WebBrowser controls! VARIANT Vinfo; VariantInit (&vinfo);p Newdlg->m_sa. Navigate (strURL, &vinfo, &vinfo, &vinfo, &vinfo);}
⑤ finally solved a small problem: there will be a warning when you open the Web page
Workaround: Find the property of the control and change the value of silent to true.
PostScript: I Caishuxueqian, welcome to propose bug
MFC controls Microsoft Web browser Simple Browser implementation