Building a Browser for Liberty Basic
IMPORTANT: You must have Internet Explorer version 5 or higher installed to use the browser!
[Editors Note: This article and demo were written late in 2002 for the LB 10 Year Anniversary Contest.]
Well, what can I say, Christmas is coming up and another year is almost gone. I was sitting around just twiddling my thumbs, writing a little code and just generally not doing anything very productive as far as programming goes. Several things simmering on the back burner but nothing peaked my interest at the moment. Then a little note popped into the old "in" basket about a contest for Liberty Basic. Now there's something to get the old interest up and going full blast! I had been away from Liberty Basic for a while persuing other languages and hadn't had a chance to really try Liberty Basic Ver. 3.02.
I thought that a contest was a good idea and just might get my interest in LB peaked again. Besides I had very recently ran across a new free 32 bit dll that incoorporates the Internet Explorer© web control into a parent program. Since it looked very easy to use, I decided to see how hard it would be to use with Liberty Basic 3.02. It turns out, very easy in fact. I thought that maybe the number of lines limitation of the unregistered copy might not allow me to write enough code but that was soon to be proven untrue. Less than 350 lines of code did the trick. One caveat though, you must have Internet Explorer© version 5 or higher to use the browser. The docs say that you can use version 4 or later but it wouldn't work for me. After upgrading to version 5.xx, it worked fine.
In my code I create a window and add a few buttons to use the minimal functions included in the dll such as "Back", "Forward", "Home", etc. All of the same functions can be found in the menu along with other functions to accomadate the running of the program. I put a menu item to load a local file from the users hard drive.
I added tooltips to the buttons to add a little more information for the user. In the code I check the version of the users system and don't add the tips if the program is run on Win NT, Win 2000 or Win XP.
Another interesting bit of code is the routine used to change the bitmap button backgrounds to that of any color scheme that may be present on the users system. I picked up this code from Alyce Watsons site [http://alycesrestaurant.com]. (Thanks Alyce!) Her site is THE place to go if you need a little snippet or two of code to speed up your programming. If you can't find it there, chances are it's not been coded yet. Many thanks to her and everyone else who gives of their time and energy to help us LB'ers!
I also provide a routine to save a minimal "favorites" listing of URLs that the user wants to remember. In the code I check to see if such a file (url.dat) exists and if not, create one during the first run of the program. I add one URL, www.libertybasic.com, and close the file.
During subsequent runs the user can add as many URLs as they want. Each time the program is run or a URL is added to the list, this file listing is read, checked for duplicates, and the URLs
added to the URL combobox for the users convenience.
The functions provided by the dll are mostly in the DoPageAction() dll call. This call provides the basic browser functions of "back", "forward", "home", "search", "refresh", "stop loading", etc. The DisplayHTMLPage() dll call loads the page to be viewed into the IE Web Control window. The EmbedBrowserObject() call sets up the control and embeds it into the child window provided by the program.
IMPORTANT EmbedBrowserObject() must be the first call to the dll after opening the dll!
UnEmbedBrowserObject() does the reverse. It releases the memory used and removes it from the system. Call this at the end of your program just before exiting. The only call not implemented in this program is the DisplayHTMLStr(). I tried it several ways and never got it to work right. This is a crucial call because of the possibility of writing a super HTML editor using the IE control. You could do the editing in a regular Liberty window and instantly view it in this control. Think of the possibilities!
Some of the normal browser functionality cannot be provided for the user by this dll at the present time. The display of a URL that the user clicks on in the control can't be retrieved so that it can be displayed for the user, for instance. The dll simply has no functions to do this. The user can move around normally, load pages, download files, etc. but can't look at an updated URL display. You can, however, right click and retrieve URLs from the built in menu provided by the control. All of the normal functions that IE provides are there.
The Browser.Dll used in the browser is based on VC++ code by Jeff Glatt but compiled using Lcc-Win32 by Kevin Diggins. The original VC++ source code for the cwebpage.dll (the original name for the dll) and more information can be found at
The Lcc-Win32 source and binary code can be found at the Yahoo BCX egroup site located at
Both the original and the ported code is freeware.
Exported functions in the Browser DLL:
Not many, only 5 functions, but enough for a fairly functional browser. The Liberty Basic code for each function is described in the browser.hlp file that is included with the LB Browser source files. Please see this and the source code for more information on using the dll.
Internet Explorer, IE, Internet Explorer Web Control are Copyright © Microsoft Corp.
Doyle Whisenant - email@example.com