Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
Immediate Solutions
Creating A Web Browser
The Testing Department is calling again. They need a new Web browser program right away. Whats wrong with the old one? you ask. They say, it doesnt display the founders picture. Oh, you say.
Its easy to build a Web browser in Visual Basicyou just use the Microsoft WebBrowser control. In this and the next few topics, well put together the functioning Web browser that you see in Figure 21.1. Our browser will support Back, Next, Home, Stop, and Refresh buttons, as you can see in that figure. In addition, the browser will have all the power of the Microsoft Internet Explorer (largely because it is the Internet Explorer; we use the WebBrowser control, which is the Internet Explorer in a control). To let the user navigate, well include a combo box, as you see in Figure 21.1. When the user types a new URL in the combo box and presses the Enter key, well navigate to that URL (and keep a record of the URLs weve been to in the combo boxs drop-down list).
Figure 21.1 Our Web browser.
To create our Web browser, follow these steps:
1. Create a new standard Visual Basic project.
2. Select the Project|Components item.
3. Click the Controls tab in the Components dialog box.
4. Select the Microsoft Internet Controls and Microsoft Windows Common Controls entries, and click on OK to close the Components dialog box.
5. Add a WebBrowser control and a toolbar to the form, stretching the WebBrowser control, WebBrowser1, to fill the space under the toolbar.
6. Add five buttons to the toolbar (right-click the toolbar, select the Properties item, click the Buttons tab, and use the Insert Button button to add the buttons).
7. Give the buttons the same captions and Key properties: Back, Next, Home, Stop, and Refresh (for example, the button with the caption Back will also have its Key property set to Back so we can identify which button in the toolbar was clicked).
8. Add a combo box, combo1, to the end of the toolbar (draw the combo box in the toolbar to make sure its part of the toolbar; dont double-click to create a combo box and then move it to the toolbar).
That sets up the Web browserbut how do we work with it in code? Well take a look at that in the next few topics.
Specifying URLs In A Web Browser
Now that youve set up the controls well need in a Web browser (see the previous topic), how do you let the user navigate?
You use the WebBrowser controls Navigate method. Lets see this at work. For example, when our Web browser first loads, we can navigate to the Microsoft Web page this way (note that you can specify URLs with or without the http:// part in the Internet Explorer, and although we omit it here, you can include that prefix if you prefer):
Private Sub Form_Load()
WebBrowser1.Navigate "www.microsoft.com"
...
End Sub
We also want the user to be able to navigate to a new URL, and thats usually done with a combo box like the one we added to our Web browser in the previous topic, combo1. We start working with combo1 by displaying the present URL and adding it to the combo boxs drop-down list:
Private Sub Form_Load()
WebBrowser1.Navigate "www.microsoft.com"
Combo1.Text = "www.microsoft.com"
Combo1.AddItem Combo1.Text
End Sub
Users can select past URLs from the combo boxs drop-down list. When they do select a URL that way, a Click event is generated, and we can navigate to the newly selected URL this way:
Private Sub Combo1_Click()
WebBrowser1.Navigate Combo1.Text
End Sub
In addition, users can type a new URL into the combo box and press Enter, just as they can in commercial browsers. When they press Enter, we can navigate to the new URL simply by calling the Combo1_Click event handler directly from the KeyPress event handler:
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Combo1_Click
End If
End Sub
Finally, when the downloading process is complete, the WebBrowser control fires a DownloadComplete event, and we can display the present URL in the browsers title bar, just as any commercial browser might. To do that, we get the browsers present URL from its LocationName property:
Private Sub WebBrowser1_DownloadComplete()
Me.Caption = WebBrowser1.LocationName
...
End Sub
In addition, we can add that URL to the top of the combo boxs list this way:
Private Sub WebBrowser1_DownloadComplete()
Me.Caption = WebBrowser1.LocationName
Combo1.AddItem WebBrowser1.LocationURL, 0
End Sub
And thats itnow the user can navigate around using the combo box. However, we have yet to make all the buttons, such as Back, Forward, and Home, active, and well do that in the next two topics. The code for the browser, browser.frm version 1 (version 2, which is included on the accompanying CD-ROM, will include support for the browser buttons), appears in Listing 21.1.
TIP: In our example, we made the Web browser navigate to the Microsoft home page when the browser is first opened. However, you can make the browser start with the users home page (as recorded by the Internet Explorer) with the browser controls GoHome method.
Previous
Table of Contents
Next
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.
Wyszukiwarka
Podobne podstrony:
701 Koszty prenumeraty prasy na 2011 poniesione w 2010701 703699 Ewidencja księgowa wpłat na PFRON699 03demo cgi 701701 704www mediweb pl?ta print php id=699701 acwww mediweb pl?ta print php id=701ld 701699 13demo cgi 699MaxCom KXT 701więcej podobnych podstron