| Wouldn't it be great if you could just pop in a custom control, and within ten or fifteen minutes have a fully working browser? Well, there's always hope! Microsoft has released, free of charge, the Internet Control Pack (ICP) which is a collection of OCX Active-X controls you can pop straight into Visual Basic! Within ten minutes or so of reading the documents and playing around, you can incorporate full functionality for HTML, FTP, news, email and HTTP into your applications. Never before has creating Internet applications been so easy! Side Effects:The latest version of the Microsoft Internet Control Pack can be downloaded from Microsoft's homesite, where an entire section on the ICP can be found. Samples, examples, and an online language reference can be viewed. The ICP page is located at http://www.microsoft.com/icp/. Alternately, if you find the connection too slow, you can download the latest version which is mirrored here:http://www.geocities.com/SiliconValley/3086/msicp.zipInstallation of the ICP is relatively straightforward. After running the install program, load up Visual Basic. You'll need to add the new HTML control into Visual Basic before you can use it. To do this, click on Tools, then Custom Controls. A list of controls will appear. Select the HTML client control, and make sure it is checked. Now, you will need to click on Tools, then References. Make sure the following items are checked Microsoft HTML Client Control Microsoft Internet Controls Microsoft HTML Intrinsic Controls Microsoft Internet Support Objects You should now find that there is a new custom control (HTML) available to drag onto your projects. Installation is complete!Start with a blank project, and drag a HTML control onto the form. The control looks similar to a textbox at design time. Make sure it is tall and wide enough to look reasonable for a browser window, and add a textbox for typing a URL. You'll also need to add a button, into which we add the following line. Private Sub Command1_Click() HTML1.RequestDoc Text1.Text End Sub Run this now, and realise that within just a few minutes you've introduced HTML support into an application! Imagine what you can do in ten or fifteen minutes! Here are some more complex things you can add:Now add a HTML control to your form, and drop in a combo box for storing the current and previous URL's. Add a caption "URL :" and place it just to the left of your combo box. To display status information for the user (such as whether or not a page is loading, when it is finished, etc) add a label called status to your form. Whenever HTML events occur, we will update the label's caption. Finally, using the Visual Basic Menu Editor (from the Tools menu), create the basic menus that will be required for the browser. If you have never used the features of the menu editor before, consult your online help or the VB reference manuals. You'll need to define the following menus :- &File....E&xit&View....View &Source....View &Document For those that are a little unsure what these menus mean, I'll briefly go through the way in which menus are created. Placing an ampersand (&) in front of a character makes it an underlined character (eg File). When you hit the alt key to access the menu, hitting V for example opens up the View submenu. The next thing of importance is the indentation of the menus. By indenting a menu (using the -> key from the Menu Editor), it places the item in a submenu. Execute the application and see how it works. Before I begin, I should point out that much of the code for the history list comes from examples provided by Microsoft. That aside, lets take a look at what events we need to code for the combo box. The first event is Combo1.KeyDown, which will be used whenever the user hits enter in the combo box (indicating he or she wants to access a new URL). Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer) 'Access new URL only if user presses enter If KeyCode = 13 Then HTML1.RequestDoc Combo1.Text End If End Sub Now you might be thinking that we should add the URL to the combo box if the user presses enter. That would work, but then the history list might then contain invalid URL's (for example, an incorrect hostname). Instead we place the combo insertion code inside of the HTML1.BeginRetrieval event. Private Sub HTML1_BeginRetrieval() 'Notify user we are receiving document Status.Caption = "Receiving " & URL Dim strURL As String ' String variable for the URL. strURL = HTML1.URL ' Set the variable to the the URL property. Dim bFound As Boolean ' Flag for search. Dim i As Integer ' Counter variable. For i = 0 To Combo1.ListCount - 1 If Combo1.List(i) = strURL Then bFound = True Exit For End If Next i If Not bFound Then 'Add the URL to the combo box. Combo1.AddItem strURL End If Combo1.Text = strURL End Sub Status/Error Messages Whenever an application calls the RequestDoc method, we need to notify the user that an attempt is being made to access the URL. Private Sub HTML1_DoRequestDoc(ByVal URL As String, ByVal Element As HTMLElement, _ ByVal DocInput As DocInput, EnableDefault As Boolean) 'Notify user we are contacting HTTP server Status.Caption = "Contacting " & URL End Sub If the user issues a request to connect, and an error of some kind occurs, the browser must indicate an error status. Private Sub HTML1_Error(Number As Integer, Description As String, Scode As Long, _ Source As String, HelpFile As String, HelpContext As Long, CancelDisplay As Boolean) 'Notify user some error has occurred with the network Status.Caption = "ERROR" End Sub We've added a receiving document status message inside the HTML1.BeginRetrieval event above when processing the combo box. Now we must write the code for the EndRetrieval event, which occurs when RequestDoc has returned the URL (including all text and images on a page). Private Sub HTML1_EndRetrieval() 'Notify user retrieval has been completed Status.Caption = "Done" End Sub View Menu This is probably the simplest feature of all. In order to allow the user to view the source of a HTML document, or to switch back into browsing mode, all that we have to do is alter the status of the boolean HTML1.ViewSource. Private Sub View_Source_Click() 'Let viewer view source HTML1.ViewSource = True End Sub Private Sub View_Doc_Click() 'Let user see original HTML document HTML1.ViewSource = False End Sub |
15 minute WWW browser |
Freelance ASP PHP web development | Web developer India Web development India| Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design