A new webpage window is displayed in the VC and webbrowser controls.

Source: Internet
Author: User

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/>} 

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.