When you use the webbrowser control to browse a webpage, a new webpage window is usually displayed. If you do not have any control, it will be opened in the default browser (usually IE, in this way, the new window is opened, and the original program is difficult to control, and the session sharing problem between the webbrowser control and IE exists. The solution is to enable the newly opened webpage to be opened in its own dialog box. The specific steps are as follows:
1. Create a dialog box-based MFC program. The dialog box ID is idd_shell_dialog, add the Microsoft Web browser control (ID: idc_explorer), and generate the control variables m_webbrowser and navigate () of idc_explorer using the wizard () you can connect to the web page you want to browse.
Variant vinfo; <br/> variantinit (& vinfo); <br/> m_webbrowser.navigate ("http: // ×××", & vinfo, & vinfo );
2. Create a dialog box (ID: idd_dialog_new) for the displayed webpage, and generate the cnewdlg class (: Public cdialog) using the Wizard to add classes ).
Add the Microsoft Web browser control (ID: idc_assumer_new) in the dialog box ),
Use the Wizard to generate the idc_explorer control variable m_newwebbrowser,
3. Add the newwindow3 () event of the webbrowser control (idc_explorer) to the original dialog box (idd_shell_dialog). When the event is triggered, a new dialog box is displayed and the webbrowser control (idc_javaser_new) in the new dialog box is used) just open the URL.
Void cshelldlg: newwindow3explorer (lpdispatch * ppdisp, bool * cancel, unsigned long dwflags, lpctstr bstrurlcontext, lpctstr bstrurl) <br/>{< br/> // todo: add the Message Processing code <br/> * cancel = true; <br/> variant vinfo; <br/> cnewdlg * newdlg = new cnewdlg; <br/> newdlg-> Create (idd_dialog_new); <br/> newdlg-> showwindow (sw_show); <br/> newdlg-> m_newwebbrowser.navigate (bstrurl, & vinfo, & vinfo, & vinfo, & vinfo); <br/>}< br/>
4. What should I do if I operate in the new window and create a new window? Add the newwindow3 () event of the webbrowser control (idc_explorer_new) in the new dialog box (idd_dialog_new) Following step 3. The new window is reversed and only one template is required, you do not need to add a new dialog box.
Void cnewdlg: newwindow3assumernew (lpdispatch * ppdisp, bool * cancel, unsigned long dwflags, lpctstr bstrurlcontext, lpctstr bstrurl) <br/>{< br/> // todo: add the Message Processing code <br/> * cancel = true; <br/> variant vinfo; <br/> cnewdlg * newdlg = new cnewdlg; <br/> newdlg-> Create (idd_dialog_new); <br/> newdlg-> showwindow (sw_show); <br/> newdlg-> m_newwebbrowser.navigate (bstrurl, & vinfo, & vinfo, & vinfo, & vinfo); <br/>}