Welcome to this advanced technique created by myself. In this technique we'll learn how to create custom controls for VB-DOS Professional Edition (this is the only one that allows us to create custom controls). When you design a dialog in VB-DOS, you have a form (on the right) and a toolbox (on the left) where all the controls that you can insert on the form are. in VB-DOS Professional, there's a way to add controls that aren't on that toolbox by default. These are what's known as a custom control.
In this technique we'll create a custom control and see how to use it in a typical application's form design. In the next section I'll explain what you will need to create the custom controls and the steps involved in creating the control.
WHAT YOU WILL NEED:
In order to create custom controls there's a couple things you'll need to make sure you have. If you don't have everything, don't worry, you can still learn how things work, but to create your own custom controls you'll need to see if you can find what's listed here.
- Visual BASIC for DOS Version 1.00 Professional Of course, without this one, it will be hard to try things out. But again this is a technique and techniques are meant to be read and understood so you won't really need VB-DOS Professional to follow clearly what i'll be talking about here.
- M.A.S.M. Version 6.5 (16 bit Macro Assembler) Indeed, VB-DOS is a 16 Bit development system. Hence the assembler needed must be able to produce 16 bit compliant code. I'm not sure if there's a valid substitute for MASM 6.5 perhaps version 6.11 of MASM may work. Note that the generated code (that's created by CUSTGEN.EXE (spin.bas) mentions MASM 6.0 so perhaps that's the version needed, or better.
GETTING STARTED: Let's get right to it. I'm not going to invent a control because that would make this technique so long to read that even I couldn't stay up long enough to write it. So, we'll be using a control that's been created already, it comes with your Visual Basic for DOS installation, in the INCLUDE directory. it's has 4 files total that are called SPIN.BAS, SPINREG.ASM, SPINDEMO.FRM and SPINDEMO.MAK respectively.
- SPIN.BAS (Generated with CUSTGEN.EXE) This file is the core file of the custom control. A spin control is basically a control with an up and a down arrow and allows the user to increase or decrease a numerical value by clicking on the up and down arrows. The .BAS file is generated at first and all you have to do fill in the subs and functions representing the events that you have selected to implement.
- SPINREG.ASM (Generated with CUSTGEN.EXE) This is an Assembler file, generated by the Custom Control tool (CUSTGEN.EXE) provided by Visual Basic for DOS Professional only. It holds registration values and code used to recognize the control as a valid and useable control in the VisualBASIC for DOS Integrated Development Environment I.D.E. In most cases there's no need to change this file per se, if a change is needed it will be generated by CUSTGEN.EXE itself.
- SPINDEMO.FRM (Control Test Form) Spin demo is a simple form, that's been created in VB-DOS's Form designer itself, it is used only to test out the control and is not part of the control itself.
- SPINDEMO.MAK (The Spin Demo Project File) Quite simply this .MAK file is just the project file that loads in the VB-DOS environment to allow to compile and test things out.
ABOUT THE CUSTOM CONTROL GENERATION TOOL (CUSTGEN.EXE):
CUSTGEN.EXE is a utility that you use when you want to create custom controls. When you double click on it, or execute it. you can see the main screen which looks like this:
You need to specify a Control Name and select the properties you'll want your control to have and the methods you'll want your control to manage. You can also select which language to generate the control template that you will be modifying. Finally, you can also specify if the control will be a container control. A container control is a container which can hold other controls within itself. For example a form is a container control because it can hold other types of controls in itself.
The list of Possible Events on the left can be changed, there are more events than those you can see on that list. To add to these events just click the Events button on the right, it will bring you to a this following dialog.
The list on the left is the list of events that are already available, as you can see by the fact that the list on the right is empty (by default) all events are available, if you don't want to see some of those events you can take them out of any list by clicking on the event or events you don't want and clickin the -> button, you'll see them get deleted from the list on the left and added to the list on the right. when you're done, just click the OK button to go back to CUSTGEN's main screen.
As you might have noticed when designing forms in VB-DOS, when you insert a control on a form, they each have their properties that you can set. For example, you can change the caption property of a label control to change what is displayed on the screen for that given label control. Just like the events, you can select what properties you want your control to allow to change. On the main screen, click the Properties button on the right and you'll see this screen:
Just like the list of events, all you need to do is take away the properties you don't want shown for your control. This is done by selecting the properties from the list and hitting the -> button to add them to the list of "not available" properties.
Once you have everything entered, properties and events selected and you are ready to create the custom control you just hit the Generate button, this will bring you to this screen:
Just enter a name for the Assembler Registration IsHandler (SPINREG.ASM was used for this purpose in the SPIN control) and the control name (which will be a .BAS file if you selected BASIC from the languages on the main screen, SPIN.BAS in our sample control). Once that's done, hit the OK button and CUSTGEN will create the control template for you. Then all you need is to edit the .bas file to implement the methods/events that you wanted to implement by adding the code you want executed for each of these events.
NEXT AND FINAL STEP, COMPILING AND LINKING EVERYTHING:
Indeed, at this point, everything is generated, you've properly inserted the code in the different event methods you wanted to and you are now ready to create the control itself. In VB-DOS a custom control is quite simple a library / Quick Library set of files. I'm assuming here that you have MASM and VB DOS installed and that your PATH variable is setup to have the MASM an VB-DOS paths added and ready. In order to get that set of files, here are the steps required:
- Compile The Registration file SPINREG.ASM To do this step, you need to call the MASM compiler with the following:
ML -c SPINREG.ASM This will create a file called SPINREG.OBJ that you'll need in step #4
- Compile The Control File SPIN.BAS You'll need the Visual Basic for DOS compiler for this step, you'll just need to use the following syntax to compile the file:
BC /x /o SPIN.BAS
- Delete or Move Existing Library of the same name SPIN.LIB This is just to avoid any possible problems with the LIB.EXE library manager if the file it wants to generate already exists.
- Create the lib for needed for the control SPIN.LIB This is done with the LIB.EXE utility included with Visual Basic for DOS Professional. Just type in the following command:
- Linking it all together in VBDOSQLB.LIB This is done with the LINK.EXE utility, also included with Visual Basic for DOS Professional. Just type in the following command:
LINK /Q spin.lib,spin.qlb,,VBDOSQLB.LIB;
As you know, the I.D.E. allows the loading of only one Quick Library (.QLB) file per session. You can of course combine multiple controls into one bigger Quick Library so that all controls can be used at once. To do so, just follow these 3 steps:
- Delete the existing library if it exists already Again this is to avoid possible conflicts and anbiguous problems if the lib file does exist already at the time you create the library file. In DOS, Just type:
DEL <CombinedLib.LIB> and press enter.
- Combine All the desired libraries together in one file. You'll need the LIB.EXE utility again here to accomplish this second step . Just type:
- Linking it all together Here, like when creating a custom control, you'll need LINK.EXE to accomplish this step. The command is:
LINK /Q <CombinedLib.LIB>,<CombinedLib.QLB>,,VBDOSQLB.LIB;
If all went well, at this point you should now have a SPIN.LIB library, it's Quick library equivalent SPIN.QLB and a VBDOSQLB.LIB that has the regular VB-DOS default controls as well as your custom control ready to be used in your projects that is if you have Visual Basic for DOS version 1.0 Professional and MASM handy on your hard drive.
As always I hope this technique proves useful to at least one of you. Most of this was created from memory (and with testing of the spin control itself) so if I've omitted something you feel might be important to add, drop in an email at the email listed below and I'll see about correcting things as soon as possible.