The Liberty Basic Newsletter - Issue #82
© 10-Oct-2000 Cameron Arnott
All Rights Reserved
In this issue:
Attachments:
Proposed For Future Issues:
  • Depends on what I receive and what I have time to write!

Starting Liberty BASIC by clicking on your program Back to the Top

If you are like me and try out lots of different Basic programming languages, then you'll find that you can't remember which *.BAS file goes with which basic.  Don't worry there is a light at the end of the tunnel. In some "Basic"'s (I can't say all because I don't know for sure) you don't have to have the file extension as .BAS.

For example I use
  • .LB1 for Liberty BASIC V1.x
  • .LB2 for Liberty BASIC V2.x
  • .RQ  for RapidQ
Extensions you could try with other BASICSs
  • .VB for  Visual Basic
  • .Q-B for Qbasic
  • .GF  for GFA Basic
  • .D-B for Dark Basic

You get the idea?
Just be sure to check for existing extension associations before you try out these suggestions.  Talking about extensions leads me onto starting Liberty BASIC by clicking on your newly renamed files.  First of all you'll need to associate the extension with Liberty BASIC.  To do this under Windows 95/98/2000/ME, double click on your program.  It will come up with something like this:

OpenWith.gif
Click on "Other", then select the program you want to launch this type of file.  In my case as stated above ".LB2" will be associated with "LB2Beta2.exe" and ".LB1" will be associated with "Liberty.exe" and ".RQ" to "JFE.exe" my preferred editor.
Under Windows 3.x you do the following (Sorry no screen shots)
  • Go into File Manager.
  • Under the FIle Menu, click "Associate".
  • In the extension box type the extension.
  • In the "with" box, type the path and name of the executable file to launch.
Now that you have that set up, don't forget to save your files as "*.LB2" "*.LB1" etc. Since LB2 beta2 now uses a default requester of "*.bas", when you load up Liberty BASIC manually then go to "Open" it won't show any of your files.  The fix for this is simply to go to the text box that is displaying "*.BAS" and change it to "*.LB2" or the extension you've decided to use.   Hopefully, Carl will be changing LB2 so that you can set your own default extension in the preferences.

Don't forget that every time you update LB2, you'll have to edit the file associations to link to the new executable.

You can expand on this to automaticly get Liberty BASIC to run your program when you click on it.  When you have a finished product that your not going to edit anymore, you can change the extension to something else, so long as it isn't already in use.  Or under Windows 95/98, you can add a second option to the same association by doing the following: Open a Window that contains a view on your system (any drive will do), select the "View" menu, then select "Folder" options and then click on the tab "File types".  You should something like this:
foldopt.gif
Scroll down to your file association you created before.  Highlight it, then click on the "Edit" button. You'll get something like this:
edfiletype.gif
You can now edit the text in the top box to whatever you like.  To edit the file, you want to open your file with click "Open" then click the "Edit" button and change your settings in there.
OpenWith.gif
To add a new function, such as to get the file to automatically run Liberty BASIC, click on the "New" button, which will bring up a new window like this.
NewAction.gif
Fill it in like i have (browsing for the file you want to launch is recommended in order to obtain the correct path).   Then tack on the end of the executable name: " -r" (Liberty BASIC's command line flag to auto run).   If you want to minimize Liberty BASIC add the following as well: " -m" (NOTE: under the current release ie: LB2 beta2 the -m option doesn't work yet).   Then click on the "OK" buttons to get all the way back out.

Windows 3.x users, I think you'll have to change the extension and then add " -r -m" to the end of the command line for Liberty BASIC.

Adding a Popup Menu To a Menu Item
DEVELOPED BY BRENT THORN
Back to the Top
We can add a list of recent files to the open source LB Editor. First, we'll create an array to hold the three most recently opened file names:

dim recentfiles$(3) 'array to hold recent files

Whenever a file is opened, it will be added to the top of the recent files list, which is held in the array. The [open] routine begins with a filedialog. If the user does not choose a file, the routine is aborted. If the user does choose a file to open, we GOSUB [recent.files] to add this new file name to the list.

[open]
filedialog "Open file..",filePath$+"*.bas",file$
if file$="" then [loop]
gosub [recent.files]


The list is easily managed in an array. We first move the filename that was in the second position to the third postion. This bumps the file name that WAS in the third position off the list. Then we move the filename that was in the first position into the second position. Last, we place the file name that was just chosen by the user into the first position:

[recent.files]
recentfile$(3)=recentfile$(2)
recentfile$(2)=recentfile$(1)
recentfile$(1)=LOWER$(file$)
RETURN

In this way, we always have a current list of the most recently opened files. To access them, we need a RECENT FILES menu:

Menu #1, "Recent",_
"File 1", [File_1],_
"File 2", [File_2],_
"File 3", [File_3]

We'll need to place routines into the branch labels for the three files, so that the proper file is opened and loaded when the user clicks the menu item. We'll first check if a file name exists in the list, and if not, we'll abort the loading. Note that the array contains empty strings until members have been added with the [recent.files] gosub routine. If a file name has been added to the list, we go to the file loading routine, and that file will be displayed in the Open Source Editor.

[File_1]
if recentfile$(1)="" then [loop]
file$=recentfile$(1)
GoTo [loadFile]

[File_2]
if recentfile$(2)="" then [loop]
file$=recentfile$(2)
GoTo [loadFile]

[File_3]
if recentfile$(3)="" then [loop]
file$=recentfile$(3)
GoTo [loadFile]

This is really all we need to do to include a list of recently opened files, but it would look more professional to append this list as a cascading popup menu to an existing menu item, as Brent Thorn has shown us. First, we add an item to the File submenu to hold this Recent Files menu popup:

menu #1, "∓mp;File",_
"∓mp;New", [new],_
"∓mp;Open", [open],_
"∓mp;Save", [save],_
"Save ∓mp;As", [saveas],|,_
"∓mp;Print", [print],_
"E∓mp;xit", [quit],_
"∓mp;Recent", [loop]

The branch label given for execution of this menu item is the input loop. The designated branch label will never actually be used, because we will add the Recent Files popup menu here.


Now, add a GOSUB to remove the top-level Recent submenu and add its menu items to the File --> Recent menu item.

gosub [remove.menu]


To work with menus, submenus and menu items, we need to obtain the handles. First, we need a handle to the menu bar itself and we get it by passing the window's handle (in this case it is "h") to the GetMenu call and retrieving the menu bar handle, which Brent calls hMenu1:

CallDll #user, "GetMenu",_
h as word,_ 'window handle
hMenu1 as word 'returns handle of menu bar

Once we have the menu bar handle, we use it to retrieve the handles to the submenus we want to modify. A submenu appears as a word on the menu bar, and a submenu is the first parameter in the LB MENU statement. In the following example, "∓mp;Help" is the submenu name, while "∓mp;Insructions" and "∓mp;About" are menu ITEMS:

menu #1, "∓mp;Help", "∓mp;Instructions",[instructions],"∓mp;About",[about]

To get the handle of a submenu, we need the menu bar handle and the position of the desired submenu. Positions are numbered beginning at 0, so the first submenu (for us, the FILE submenu) is at position 0. Our RECENT submenu was placed third on the menu bar, so it is in position 2.

CallDll #user, "GetSubMenu",_
hMenu1 As word,_ 'handle of menu bar
0 As word,_ 'position of sub menu desired 0 - first
hmenuFile As word 'handle of sub menu for File menu

CallDll #user, "GetSubMenu",_
hMenu1 As word,_ 'handle of menu bar
2 As word,_ 'position of recent menu 2 = third
hmenuRecent As word 'returns handle of recent menu

Now that we have the handles of the two submenus, we can make some changes. We modify a menu with the USER function, ModifyMenu. It requires the handle of the submenu that will be modified, and the position of the menu item within the submenu that will be changed. In our FILE submenu, the RECENT menu item is the 8th item, and so it is in position 7. The third parameter needed by the ModifyMenu function is a numeric value that represents instructions to the function that tell it just HOW we want to modify the menu item. The values for each of the instructions are added together, and the resulting single value tells windows just which instructions are being issued.

The instructions we will give include telling the function that we are specifying the menu item to modify by its position, not by its handle. (Had we wanted to use the menu item's handle, we would have needed to retrieve it with yet another api call.) Another part of the instructions tells the function that we want to add a popup menu to a menu item, and another one tells the function that we are giving a name (string) to the menu item.

The value for the POSITION instruction is 1024. The value for the POPUP instruction is 16. The value for the STRING instruction is 0. We can set the flags in either of these ways:

menuflags = 1024 + 16 + 0

OR, we can do the math ourselves:

menuflags =1040

Windows has predefined constants for these values, which are recognized by Liberty BASIC when an underscore is placed in front of the value name. MF_BYPOSITION becomes _MF_BYPOSITION in LB syntax. To "add" constant values together, use the bitwise "OR" operator:

menuflags = _MF_BYPOSITION Or _MF_POPUP Or _MF_STRING

Any of the previous three examples will properly set the instruction flag for the ModifyMenu function. After the File submenu handle, the position of the menu item to modify, and the instruction flag, we place the handle of the popup menu to append to the RECENT menu item. Windows knows to add this popup, because we gave it the MF_POPUP instruction. The last parameter is the text string that will be contained on the menu item. This can be the same as the original string name of the menu item, or it can be completely different.

CallDll #user, "ModifyMenu",_
hmenuFile As word, _ 'handle of menu to modify
7 As word,_ 'position of item to change (8th item)
menuflags As word, _ 'flags for type of change
hmenuRecent As word,_ 'menu to add as a popup
"∓mp;Recent" As ptr, _ 'name of menu item
result As word


We are now good to go. When the FILE submenu is activated, we see that there is an arrow next to the RECENT menu item, indicating a cascading popup menu. Moving the mouse to this item activates the popup menu, and we can click on "File 1", "File 2", or "File 3" to reload a previously opened file.

There is one last task to perform. Since we have appended the RECENT submenu to an item in the FILE submenu, we no longer need to have it show on the menu bar. We call RemoveMenu to remove the RECENT submenu. This removes the submenu from the bar, but does not destroy it. It remains in memory, to be accessed through the FILE submenu, RECENT menu item.

CallDll #user, "RemoveMenu",_ 'remove recent menu from view
hMenu1 As word, _ 'handle of menu bar
2 As word,_ '2 = position of menu to remove
_MF_BYPOSITION As word, _ 'flag for remove by position
result As word

Any time a change is made to the menu bar, it must be redrawn to reflect the change:

CallDll #user, "DrawMenuBar",_ 'must redraw bar after change
h As word,_ 'window handle
result As word
RETURN


OpenSource Editor Updated With Popup Menu B>Submitted by Alyce Back to the Top
Here we have the Opensource Editor updated with the new Popup menu's Open Source Editor V1.5

Sprites in Liberty BASIC V2 Beta 2 Back to the Top
Yipee!!!!  Carl Gundel has included some sprite commands in Liberty BASIC 2 beta 2 to access Sprite02.dll written by Alyce.  Until now we've had to access the dll using the CallDLL command (which by the way you still can).  The inclusion of these commands will definitely make using sprites in our programming a lot easier.  Included in the distribution of Liberty BASIC 2 beta 2 is a Sprite help file and demo's on how to use the new commands.  I was going to write an article explaining how to use these new commands but Alyce has done a brilliant job (much better than I ever could).  There is also an update for the help file on - October 2, 2000 -- Liberty BASIC 2 updated sprite tutorial!!! - .
News Flash:  I just saw a message in the mailing list that Alyce has just fixed a bug in the sprite scrollong routines of her dll, the updated sprite03.dll can be found on Alyces web site.