![]() |
Menu |
QBasic GUI Tutorial #1In the good old days (I'm definitely getting old) when RAM was measured in bytes rather than megabytes and processor speeds were measured in single figures, most operating systems came with a programming language. DOS had QBASIC, UNIX had it's shell scripting and most micros used some variation of BASIC. This gave users access to a programming language without the need to spend money. Magazines could publish program listings secure in the knowledge that users had access to the relevent language because it was bundled with the Operating System. Then along came the GUI (Graphical User Interface) and suddenly the facility dried up. QBasic is however is still a great way to get into programming despite the fact that it hasn't been updated to allow Windows Apps to be created (although VBScript can be used to do so - see WEBlications section of this site) and it is still shipped with Windows although it is tucked away in a folder callled OldDOS on the CD. Recently however, I discovered a GUI for QBasic that has all the facilities that we have come to expect from products like Windows (overlapping windows, menu's, widgets and mouse control) that can be extended and programmed using QBasic. Here then is a good way to start learning to program and it really isn't that difficult. To follow this tutorial, you will need a copy of QBasic which can be found on your Windows CD (95/98/ME) as above or somewhere on the hard disk if you have NT4 (I have yet to find out if it is still shipped with 2000 or XP). Create a new folder on your drive called QBasic and copy the following files to it:- qbasic.exe Create a shortcut on you desktop to the qbasic.exe file and run the program. You will get something like this:-
Explore all the menu's in particular the help menu. Click on the About help menu to see what version of QBasic you are running - version 1.1 is the latest and is required for you to follow this tutorial - version 1.0 won't work You will also need a copy of the Windoze program which can be downloaded free here. There is also a textmode version which works in a similar way here and I'll be exploring that in a later tutorial. I have as yet been unable to contact the author of this program (I didn't write it) but it is Freeware and free to use provided you don't try to pass it off as your own work. So what does it do? How good is it? What does it look like? What are it's disadvantages? It provides the QBasic programmer with a tool box of commands that can be used to create a Graphical User Interface complete with Windows, mouse control, text boxes, scroll bars, buttons and a whole host of other things including the ability to load bitmaps and icons and play sound .WAV files (the textmode version also has a file selection dialogue and a task bar). It is the best GUI for QBasic I have come across and I've tried them all. It is easy to program, small in size and works quite fast. There is a screenshot here if you want to see what it looks like. I have been unable to compile it with QuickBasic 4.0 and it is very large for a QBasic program so you are restricted on the size of programs you can write unless you strip out some of the functionality (which is relatively easy to do). It is also a bit awkward when it comes to placing controls on windows as this isn't a visual environment. Up to now, support has been virtually non-existent which is why I've decided to offer these tutorials. However, the program remains the property of the author and is offered without any warranty - please read the beginning of the program for more information. Welcome to DOS GUI programming. So to begin. Make a backup copy of win2.bas and ensure that winfont.dat is in the same folder. Load the program into QBasic and read the beginning of the program which gives a very full explanation of how the program functions and how to program it. You can test the program by pressing F5 and marvel at the complexity of what can be achieved. But you'll want to create your own. The first task is of course to work out how to create a window and place it on the screen. Press F2 and select the subroutine InitScreen. SUB Initscreen '---------------------------------------------------------------------------- ' Defines the objects '---------------------------------------------------------------------------- ' This routine is called at startup '---------------------------------------------------------------------------- CreateWindow 1, 0, 0, 220, 140, "Hello", Fill, True initing = 0 END SUB Edit the subroutine to look as above by removing all the code under the underlined comments but do not remove the line of code just above END SUB as shown. Save as test1.bas and run it using F5. After clicking on the splash screen, you will see a Window which can be clicked on and moved when the caption (called simply Hello) is clicked on and the left mouse button is held down in the usual way. The program can be stopped using CTRL BREAK and is currently the only way to stop it. However, we can do something about that. Search for the word user and you will come across something like this: '---------------------------------------------------------------------------- This will have a block of code followed by:- '---------------------------------------------------------------------------- IF ClickedButton = 7 THEN Now go back to the subroutine InitScreen and modify as follows: SUB Initscreen '---------------------------------------------------------------------------- ' Defines the objects '---------------------------------------------------------------------------- ' This routine is called at startup '---------------------------------------------------------------------------- CreateWindow 1, 0, 0, 220, 140, "Hello", Fill, True CreateButton 1, 7, 80, 70, 100, 30, "Quit" initing = 0 END SUB
|
| Written by Nick Cheesman.
Last updated: 01/04/2004 Please eMail me at: nickjc@nickjc.co.uk |