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

📄 ch21.htm

📁 VC 21天 学习VC 的好东西
💻 HTM
📖 第 1 页 / 共 3 页
字号:
3:     // TODO: Add your command handler code here
4:
5:     // Stop the current download
6:     Stop();
7: }</PRE>
<P>If you run your application, you can use this menu entry to stop any download
of a Web page that you don't want to wait on. It would be more convenient if you
added a toolbar button for this menu ID.</P>
<P>Another control function that most browsers have is the capability to reload the
current Web page. This function is handy for Web pages that contain dynamic elements
that change each time the page is downloaded. It's also helpful for Web pages that
your browser may have in its cache so that it doesn't retrieve the newest version
of the page. It's necessary to be able to force the browser to reload the page and
not just display the cached version (especially if it's a Web page that you are in
the process of creating). The browser component has the capability built in with
the 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 entry
to the View menu. Specify the properties for the new menu entry using the settings
in Table 21.4. You can add a separator bar between the two View menu entries that
were originally there, and the two new entries, to make your menu look like the one
in 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>The
modified View menu.</I></P>
<P>Once you add the menu entry, use the Class Wizard to add an event-handler function
to 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 here
4:
5:     // Reload the current page
6:     Refresh();
7: }</PRE>
<P>Now you can test this functionality by finding a Web site that returns a different
page each time that you refresh the browser, such as the Random Monty Python Skit
Server in Figure 21.7. As with the rest of the menu functions that you added to this
application, 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>The
Refresh 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 a
series of ActiveX components that could be used in other applications. You saw how
Microsoft encapsulated the browser into the CHtmlView class, which can be used in
SDI 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 you
could use the dialog bar to place controls on a toolbar and how the events for these
controls can be handled in the frame class for the application. Finally, you learned
how to add menus to your application to call the various functions of the Web browser
to 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 of
the material covered and exercises to provide you with experience in using what you've
learned. The answers to the quiz questions and exercises are provided in Appendix
B, &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 programming
tasks in Visual C++, with the exception of those that require specialized knowledge
and understanding. Although there's still plenty for you to learn, you have covered
the vast majority of the topics in a very short amount of time. From here you will
probably want to delve into one or two more specialized areas of Windows programming--the
type that an entire book can be written on--because at this point, you've got just
about 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 time
once again to come up with some of your own applications where you can apply the
things you've learned. This will help pinpoint any areas that you might need to go
back and review before jumping into any more advanced topics. Let's take a quick
look 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 application
development technology, ActiveX Data Objects (ADO). You learned how ADO sits on top
of the OLE DB technology, simplifying database access considerably. You learned how
you can easily build a database application by using ADO as an ActiveX control and
connecting it to some ADO-compatible, data-bound ActiveX controls. You also learned
how you can import the DLL and dive into the code, exerting complete control over
how your application deals with the database. You learned how you can read and write
each of the fields in a record in the record set by converting it from and to the
variant data type. You also learned how you can design your own custom record class
and can bind it to the record set object, providing you with a much more convenient
way to access the individual field values in the database. If you are having problems
with 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 you
develop with other programmers, without having to share your code. First you learned
how to build your modules into library files that can be linked into applications
by other Visual C++ developers. You saw how with this approach, if any change is
made to the library module, then all the applications that it's used in have to be
rebuilt. You learned how you can create these modules without making any special
changes to the way you write your code. If you don't remember how you did all of
this, you can go back to Day 16 to review it.</P>
<P>The second way that you learned to share your functionality with other programmers
was to build DLLs. You learned how you can create two different types of DLLs: one
that can be used only by other Visual C++ applications and one that can be used by
any other application, regardless of what programming language was used to build
it. You saw how you can create a DLL for use by other Visual C++ programmers without
having to make any real changes to the way you design or code your modules. You also
learned how you need to make dramatic changes to how your module is used and interacted
with when creating DLLs that can be used by all programming languages. You learned
how 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. You
also learned how to build a definition file, with the names of all functions to be
exported 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 modules
without sharing the code was to package it as an ActiveX control. You learned how
to use the Control and Class Wizards to add in all the properties, methods, and events
that you want to have in your control. You learned how to read and write the properties
in your control. You saw how there are two different ways that the properties in
your control can be implemented, and you learned how to determine which type is appropriate
for each of your control's properties. You learned how you can raise events in the
container application from your control by firing the event in your code. Along with
all of this, you learned how you can use the ActiveX Control Test Container utility
to test your control, calling all its methods and triggering all the events that
it's capturing. You saw how you can monitor the events that your control is firing
in the containing application to make sure that they are being fired as and when
they should. If you need any reminders of how all this works, you can look back at
Day 19 for a refresher.</P>
<P>An important thing that you learned was how you can enable your applications to
perform 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 learn
how to make your applications perform multiple tasks at once, but you also learned
two different ways to do so. First, you learned about the OnIdle function and how
you can hook into this function to trigger your own functionality to be run when
the application is sitting idle. You also learned about the shortcomings of using
this approach to adding a second task to your application and how it can prevent
your application from responding to the user. You need to slice the background task
into little pieces that can be done quickly, which requires you to develop some elaborate
way of keeping track of where the task is and where it needs to pick back up when
the application is idle again.</P>
<P>The second way that you learned to give your applications a second or third task
to do is by spinning off separate threads, which run completely independent of the
main user-interface thread. You learned how to create a callback function that controls
the top level of execution for the threads and how you can start and stop the thread
as necessary. You also saw how these independent threads are completely independent
from the rest of the application and how they'll continue to run, even when the rest
of the application is also busy. If you feel the need to look at all this a second
time, you might want to read Day 18 again.</P>
<P>Another area of growing importance that you learned about was how to build Internet
applications using the Winsock interface classes. You learned how you can build one
application 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 it
is to send messages and to be notified when a message has arrived after the connection
between the two applications has been made. If you need to review some of this, you
might want to look back at Day 20.</P>
<P>Finally, you learned how you can incorporate the Microsoft Internet Explorer Web
browser into your application without any effort whatsoever. You learned how you
can control the browser by specifying the URL that it should load and display for
the user and how you can display informational messages to the user to show what
the browser is doing and when it's busy. If you need to look back at this to refresh
your 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 advanced
topics, especially over this last week. Now it's time to put this book down and get
busy programming, building your own applications using what you've learned. Good
luck. If you find that you need a little help or advice, a good place to turn is
the Microsoft newsgroups on the Internet. They are full of people who are both knowledgeable
and 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"><IMG
SRC="../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. All
rights reserved.
</CENTER>

</BODY>

</HTML>

⌨️ 快捷键说明

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