First, use vs2008 to create a dialog box-based MFC application, add the webbrowser control, and navigate!
Go to the previous blog
Http://blog.csdn.net/LightBoat09/archive/2010/12/14/6074967.aspx
This project is added to the previous project...
1. Create dialog box
ID: idd_dialog_new
Set the minimize box attribute of the dialog box to true,
The maximize box attribute is also set to true,
2. Add the webbrower Control
In the resource dialog box, right-click and select [insert ActiveX Control], select [Microsoft Web browser], and click "OK ",
Set ID to idc_assumer_new
3. Add dialog box class
On the resource dialog box, right-click ---> [add class] and the "MFC class wizard" will pop up"
Input Class Name: cnewdlg,
The default base class is cdialog,
Click "finish"
4. Add a webbrowser control variable
In the class window, select "cnewdlg" and Right-click ---> [add] ---> [add variable]. The "add member variable wizard" dialog box is displayed.
Select "control variables" (check box), select idc_explorer_new for the Control ID, enter m_newwebbrowser for the variable name, and click "finish "!
5. Now, the new page window is displayed in the self-built dialog box.
Rewrite the newwindow3assumer1 () function of the previous blog.
Void cbrowserdlg: newwindow3assumer1 (lpdispatch * ppdisp, bool * cancel, unsigned long dwflags, lpctstr bstrurlcontext, lpctstr bstrurl) <br/>{< br/> // todo: add the Message Processing code <br/> * cancel = true; <br/> cstring strurl; <br/> strurl = bstrurl; <br/> // create dialog box <br/> cnewdlg * pnewdlg = new cnewdlg; <br/> pnewdlg-> Create (idd_dialog_new, this ); <br/> pnewdlg-> showwindow (sw_show); <br/> // webpage navigation, webbrowser control in the new dialog box! <Br/> variant vinfo; <br/> variantinit (& vinfo); <br/> pnewdlg-> m_newwebbrowser.navigate (strurl, & vinfo, & vinfo); <br/>}Now, you can try to open it in a new window and display it in your own dialog box. The dialog box may be a little small,
To enable full screen, reload the oninitdialog () function of the cnewdlg dialog box class. The specific method is as follows:
6. Reload the oninitdialog () function
In the class window, select "cnewdlg" to go to [properties] and click [rewrite]. After the [event] and [Message] icons, do you still remember the lightning icon? After that, the second ...)
Click oninitdialog and add the oninitdialog function. The system automatically generates the code and then adds the maximization setting to the code...
Bool cnewdlg: oninitdialog () <br/>{< br/> cdialog: oninitdialog (); <br/> // todo: add additional initialization here <br/> showwindow (sw_showmaximized); // maximize the window <br/> crect rect; <br/> getclientrect (& rect ); <br/> // set the webbrowser control position <br/> m_newwebbrowser.movewindow (0, 0, rect. width (), rect. height (); <br/> return true; // return true unless you set the focus to a control <br/> // exception: the OCX attribute page should return false <br/>}< br/>
There is another question. What should I do if a new window is displayed in the new window ...???
You can try to search for the Baidu website in Baidu and open it. The Baidu homepage is displayed in the new dialog box,
Search for the Baidu homepage and open it. Then, open it again in the IE window. The browser is out of control ,...
Do not panic. Just generate a new window in the window... add newwindow3 message processing as follows:
7. Add newwindow3 message processing to the webbrowser control of cnewdlg in the new dialog box.
Enter the resource window. This is the new dialog box idd_dialog_new, and then go to the webbrowser control (idc_javaser_new) attribute window,
Click the control event (lightning icon), find newwindow3, and add newwindow3assumernew to the right. The code is automatically generated.
Add code in newwindow3assumernew, which is the same as newwindow3assumer1 () in step 5...
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/> cstring strurl; <br/> strurl = bstrurl; <br/> // create dialog box <br/> cnewdlg * pnewdlg = new cnewdlg; <br/> pnewdlg-> Create (idd_dialog_new, this ); <br/> pnewdlg-> showwindow (sw_show); <br/> // webpage navigation, webbrowser control in the new dialog box! <Br/> variant vinfo; <br/> variantinit (& vinfo); <br/> pnewdlg-> m_newwebbrowser.navigate (strurl, & vinfo, & vinfo); <br/>}
Now you can have a mountain in the past, a temple in the mountains, and a temple. Keep going. If you are interested, try it...
You can narrow down the window to see the effect of many arranged windows...
This ends...
Eight, there is a very serious problem, memory leakage...
C ++ is very clear, the new will have to delete...
Of course, if you can delete pnewdlg directly, it would be better if pnewdlg has disappeared...
We reload the oncancel (), onok (), and wm_ncdestroy message events in the cnewdlg dialog box.
Void cnewdlg: oncancel () <br/>{< br/> // todo: Add dedicated code and/or call the base class here <br/> // cdialog :: oncancel (); <br/> destroywindow (); <br/>}< br/> void cnewdlg: onok () <br/>{< br/> // todo: Add dedicated code and/or call the base class here <br/> // cdialog: onok (); <br/> destroywindow (); <br/>}< br/> void cnewdlg: onncdestroy () <br/>{< br/> cdialog: onncdestroy (); <br/> // todo: add the message processing program code here <br/> Delete this; <br/>}< br/>
9. When you open the webpage and close the webpage, you will still find that the memory has increased significantly, reducing the number
This Microsoft IE kernel is bad. You can use IE to open the web page and view the memory in the task manager, which also increases and decreases,
Google Chrome is not good enough...
It is said that opera controls the best (I have never tried)
To control these with code, see the http://support.microsoft.com/kb/262110/zh-cn
It was written in VB. I forgot about it. I can convert it to VC when I have time!
It's no wonder that it was written in Visual Basic. Bill Gates was so arrogant that he said, "I dare to challenge anyone with basic and welcome anyone to challenge me with basic! "