⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch21.htm

📁 visual c plus plus its a book for how to learn c plus plus in just 21 days its an easy way to lea
💻 HTM
📖 第 1 页 / 共 3 页
字号:
3:     // TODO: Add your command handler code here4:5:     // Stop the current download6:     Stop();7: }</PRE><P>If you run your application, you can use this menu entry to stop any downloadof a Web page that you don't want to wait on. It would be more convenient if youadded a toolbar button for this menu ID.</P><P>Another control function that most browsers have is the capability to reload thecurrent Web page. This function is handy for Web pages that contain dynamic elementsthat change each time the page is downloaded. It's also helpful for Web pages thatyour browser may have in its cache so that it doesn't retrieve the newest versionof the page. It's necessary to be able to force the browser to reload the page andnot just display the cached version (especially if it's a Web page that you are inthe process of creating). The browser component has the capability built in withthe Refresh function. One call to this function means the current page is reloaded.</P><P>You can add this functionality to your application by adding another menu entryto the View menu. Specify the properties for the new menu entry using the settingsin Table 21.4. You can add a separator bar between the two View menu entries thatwere originally there, and the two new entries, to make your menu look like the onein Figure 21.6.</P><P><H4>TABLE 21.4. MENU PROPERTY SETTINGS.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Object</I></TD>		<TD ALIGN="LEFT"><I>Property</I></TD>		<TD ALIGN="LEFT"><I>Setting</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Menu Entry</TD>		<TD ALIGN="LEFT">ID</TD>		<TD ALIGN="LEFT">IDM_VIEW_REFRESH</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"></TD>		<TD ALIGN="LEFT">Caption</TD>		<TD ALIGN="LEFT">&amp;Refresh</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"></TD>		<TD ALIGN="LEFT">Prompt</TD>		<TD ALIGN="LEFT">Refresh the current page\nRefresh</TD>	</TR></TABLE></P><P><A HREF="javascript:popUp('21fig06.gif')"><B>FIGURE 21.6.</B></A><B> </B><I>Themodified View menu.</I></P><P>Once you add the menu entry, use the Class Wizard to add an event-handler functionto the view class for the COMMAND event message for this menu entry. Edit the function,adding the code in Listing 21.8.</P><P><H4>LISTING 21.8. THE CWebBrowseView OnViewRefresh FUNCTION.</H4><PRE>1: void CWebBrowseView::OnViewRefresh()2: {3:     // TODO: Add your command handler code here4:5:     // Reload the current page6:     Refresh();7: }</PRE><P>Now you can test this functionality by finding a Web site that returns a differentpage each time that you refresh the browser, such as the Random Monty Python SkitServer in Figure 21.7. As with the rest of the menu functions that you added to thisapplication, this one should also be added to the toolbar.</P><P><A HREF="javascript:popUp('21fig07.gif')"><B>FIGURE 21.7.</B></A><B> </B><I>TheRefresh function will perform a new download.</I></P><P><H2><A NAME="Heading9"></A>Summary</H2><P>Today you learn how Microsoft designed its Internet Explorer Web browser as aseries of ActiveX components that could be used in other applications. You saw howMicrosoft encapsulated the browser into the CHtmlView class, which can be used inSDI and MDI applications to provide Web browsing functionality to almost any application.You learned how you can use this view class to build a Web browser. You saw how youcould use the dialog bar to place controls on a toolbar and how the events for thesecontrols can be handled in the frame class for the application. Finally, you learnedhow to add menus to your application to call the various functions of the Web browserto provide a complete surfing experience.</P><P><H2><A NAME="Heading10"></A>Q&amp;A</H2><DL>	<DT></DT>	<DD><B>Q Why is Print Preview not included on the default menus when I choose CHtmlView	as the base class for my view class?</B>	<P>	<DT></DT>	<DD><B>A</B> The printing for the CHtmlView class is performed by the browser, not	the view class. You don't have print preview because the browser doesn't support	it.	<P>	<DT></DT>	<DD><B>Q How can I get the HTML source code from the browser so that I can see or	edit it?</B>	<P>	<DT></DT>	<DD><B>A</B> The CHtmlView class has a member function, GetHtmlDocument, that returns	a pointer to the IDispatch interface of the document object in the browser. You have	to use the Invoke IDispatch function to call the functions in the document object	to retrieve the HTML source code. For documentation on how to do this, check out	the Microsoft Developer Network CD that you received with your copy of Visual C++	6.	<P></DL><H2><A NAME="Heading11"></A>Workshop</H2><P>The Workshop provides quiz questions to help you solidify your understanding ofthe material covered and exercises to provide you with experience in using what you'velearned. The answers to the quiz questions and exercises are provided in AppendixB, &quot;Answers.&quot;</P><P><H3><A NAME="Heading12"></A>Quiz</H3><DL>	<DT></DT>	<DD><B>1. </B>What does the CHtmlView class encapsulate for use in Visual C++ applications?	<P>	<DT></DT>	<DD><B>2. </B>How can you get the URL for the current Web page from the CHtmlView	class?	<P>	<DT></DT>	<DD><B>3. </B>What command is triggered for the frame class when the user presses	the Enter key in the edit box on the dialog bar?	<P>	<DT></DT>	<DD><B>4. </B>What functions can you call to navigate the browser to the previous	and the next Web pages?	<P>	<DT></DT>	<DD><B>5. </B>How can you stop a download in progress?	<P></DL><H3><A NAME="Heading13"></A>Exercises</H3><DL>	<DT></DT>	<DD><B>1. </B>Add the GoSearch function to the menu and toolbar.	<P>	<DT></DT>	<DD><B>2. </B>Add the GoHome function to the menu and toolbar.	<P>	<DT>Disable the Stop toolbar button and menu entry when the application is not downloading	a Web page.</DT>	<P></DL><H2><A NAME="Heading14"></A>In Review</H2><P>You made it! You now have the skills to tackle most of the Windows programmingtasks in Visual C++, with the exception of those that require specialized knowledgeand understanding. Although there's still plenty for you to learn, you have coveredthe vast majority of the topics in a very short amount of time. From here you willprobably want to delve into one or two more specialized areas of Windows programming--thetype that an entire book can be written on--because at this point, you've got justabout all the generalized skills down.</P><P>Just in case you don't have them all down, it's not a bad idea to take some timeonce again to come up with some of your own applications where you can apply thethings you've learned. This will help pinpoint any areas that you might need to goback and review before jumping into any more advanced topics. Let's take a quicklook back at what you should have learned during the past week, just to make sure.</P><P>You started off the week by learning about Microsoft's latest database applicationdevelopment technology, ActiveX Data Objects (ADO). You learned how ADO sits on topof the OLE DB technology, simplifying database access considerably. You learned howyou can easily build a database application by using ADO as an ActiveX control andconnecting it to some ADO-compatible, data-bound ActiveX controls. You also learnedhow you can import the DLL and dive into the code, exerting complete control overhow your application deals with the database. You learned how you can read and writeeach of the fields in a record in the record set by converting it from and to thevariant data type. You also learned how you can design your own custom record classand can bind it to the record set object, providing you with a much more convenientway to access the individual field values in the database. If you are having problemswith any of this, you might want to review Day 15 once more.</P><P>You learned three different ways of sharing the functionality modules that youdevelop with other programmers, without having to share your code. First you learnedhow to build your modules into library files that can be linked into applicationsby other Visual C++ developers. You saw how with this approach, if any change ismade to the library module, then all the applications that it's used in have to berebuilt. You learned how you can create these modules without making any specialchanges to the way you write your code. If you don't remember how you did all ofthis, you can go back to Day 16 to review it.</P><P>The second way that you learned to share your functionality with other programmerswas to build DLLs. You learned how you can create two different types of DLLs: onethat can be used only by other Visual C++ applications and one that can be used byany other application, regardless of what programming language was used to buildit. You saw how you can create a DLL for use by other Visual C++ programmers withouthaving to make any real changes to the way you design or code your modules. You alsolearned how you need to make dramatic changes to how your module is used and interactedwith when creating DLLs that can be used by all programming languages. You learnedhow to provide straight function calls as an interface for use by other applications,with all necessary information to be passed in as parameters to the functions. Youalso learned how to build a definition file, with the names of all functions to beexported included in it. If you need any reminders of how you can do any of this,you'll want to look over Day 17 again.</P><P>The third and final way that you learned to share the functionality of your moduleswithout sharing the code was to package it as an ActiveX control. You learned howto use the Control and Class Wizards to add in all the properties, methods, and eventsthat you want to have in your control. You learned how to read and write the propertiesin your control. You saw how there are two different ways that the properties inyour control can be implemented, and you learned how to determine which type is appropriatefor each of your control's properties. You learned how you can raise events in thecontainer application from your control by firing the event in your code. Along withall of this, you learned how you can use the ActiveX Control Test Container utilityto test your control, calling all its methods and triggering all the events thatit's capturing. You saw how you can monitor the events that your control is firingin the containing application to make sure that they are being fired as and whenthey should. If you need any reminders of how all this works, you can look back atDay 19 for a refresher.</P><P>An important thing that you learned was how you can enable your applications toperform more than one task at a time. This is an important piece of functionality,and more applications are requiring this capability every day. Not only did you learnhow to make your applications perform multiple tasks at once, but you also learnedtwo different ways to do so. First, you learned about the OnIdle function and howyou can hook into this function to trigger your own functionality to be run whenthe application is sitting idle. You also learned about the shortcomings of usingthis approach to adding a second task to your application and how it can preventyour application from responding to the user. You need to slice the background taskinto little pieces that can be done quickly, which requires you to develop some elaborateway of keeping track of where the task is and where it needs to pick back up whenthe application is idle again.</P><P>The second way that you learned to give your applications a second or third taskto do is by spinning off separate threads, which run completely independent of themain user-interface thread. You learned how to create a callback function that controlsthe top level of execution for the threads and how you can start and stop the threadas necessary. You also saw how these independent threads are completely independentfrom the rest of the application and how they'll continue to run, even when the restof the application is also busy. If you feel the need to look at all this a secondtime, you might want to read Day 18 again.</P><P>Another area of growing importance that you learned about was how to build Internetapplications using the Winsock interface classes. You learned how you can build oneapplication that connects to another over a network and sends messages back and forth.You learned that, just like with a telephone, for one application to connect to another,the second application has to be listening for the connection. You saw how easy itis to send messages and to be notified when a message has arrived after the connectionbetween the two applications has been made. If you need to review some of this, youmight want to look back at Day 20.</P><P>Finally, you learned how you can incorporate the Microsoft Internet Explorer Webbrowser into your application without any effort whatsoever. You learned how youcan control the browser by specifying the URL that it should load and display forthe user and how you can display informational messages to the user to show whatthe browser is doing and when it's busy. If you need to look back at this to refreshyour memory, you can go back to Day 21.</P><P>That's it. You're done. You've covered a lot of ground and learned some advancedtopics, especially over this last week. Now it's time to put this book down and getbusy programming, building your own applications using what you've learned. Goodluck. If you find that you need a little help or advice, a good place to turn isthe Microsoft newsgroups on the Internet. They are full of people who are both knowledgeableand helpful.</P><H1></H1><CENTER><P><HR><A HREF="../ch20/ch20.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../apa/apa.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <BR></P><P>&copy; <A HREF="../copy.htm">Copyright</A>, Macmillan Computer Publishing. Allrights reserved.</CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -