The magazine of the Melbourne PC User Group
QBASIC and Mouse with Click,
Double Click and Drag
Keith Phillips |
|
In PC Update, December 1997 I described how to use single mouse
clicks in QBASIC. That is extended here to include double clicks and drag. There are two new programs. The
first, named ASSEMBLY.BAS (click to view and/or download) converts
assembly code into a form that can be used in QBASIC. The second, named QB&MOUSE.BAS provided here
in three separate parts (QB&MOUSE1.BAS, QB&MOUSE2.BAS and
QB&MOUSE3.BAS) demonstrates how to use the new mouse control.
ASSEMBLY.BAS makes the DATA statements that control the mouse and QB&MOUSE.BAS displays
chess boards (Figure 1) like those published in The Age Saturday Extra and The Weekend Australian. Download
QB&MOUSE.ZIP from the BBS or make the QBASIC programs on a floppy disk and decide later whether to copy
them to another drive. Find QBASIC.EXE and QBASIC.HLP on any Windows9x CD-ROM and copy them to the floppy
disk. Go to the DOS prompt, type A: and press enter to make drive A: the default drive. Comments can be
omitted when typing QBASIC programs.
|

Figure 1. The Chess Board
|
The first 15 lines of ASSEMBLY.BAS have an improved
version of the mouse control program previously published in PC Update. The assembly code is to be
stored in an array. The DW statements reserve the first four array elements for data. The first MOV
statements copy the data into the AX, BX, CX & DX registers. Int33 runs the mouse driver (a program
loaded by Windows9x on startup) which puts its results into the registers. The next MOV statements copy the
results back into the first four array elements. There are 49 bytes of code. One more byte is added to make
an even number because they are read in pairs. It doesn't matter what the extra byte is because RETF ends the
assembly program. The Int33 functions used are listed in
INT33HEX.
ASSEMBLY.BAS uses the CVI function to convert two-character strings into QBASIC short integers. The output
of ASSEMBLY.BAS is ASSEMBLY.DAT which contains the DATA statement. If you have made ASSEMBLY.DAT, start
QBASIC with the command:
QBASIC ASSEMBLY.DAT
This forces QBASIC to load a program that doesn't have the .BAS extension. The DATA statement has all the
data values on one line, which is OK for QBASIC, but if you prefer, you can edit the data into several DATA
lines. Type in the rest of the code from QB&MOUSE1. If you haven't made ASSEMBLY.DAT, open a new file in
QBASIC and type all of the code from QB&MOUSE1.
Then type in the subroutines from QB&MOUSE2 and save the file as QB&MOUSE.BAS.
The subprograms in QB&MOUSE3 are entered into QB&MOUSE.BAS as follows: in QBASIC, move the cursor to
a blank line (a safe procedure is to press Ctrl+End) and type:
SUB AssemblyCode (ax, bx, cx, dx)
and press Enter. QBASIC opens a window for the subprogram. Type in the code from QB&MOUSE3.
Press the F2 key, return to the main program and repeat the procedure for:
SUB MouseLimits (left, right, top, bottom, col,row)
SUB PressClick (press$, click, cx, dx,presses,releases)
When you save QB&MOUSE.BAS, QBASIC will insert three DECLARE SUB statements at the top of the saved
program for its own use next time the program is loaded.
Close QBASIC and type EXIT to return to Windows9x. Double left click My Computer and double left click
Floppy(A:). Right drag the QBASIC.EXE icon, drop it in the Floppy(A:) window, and from the menu, choose
Create Shortcut(s) Here. Right click the shortcut, choose Rename and name the shortcut CHESS BOARD. Right
click the shortcut again, choose Properties, Program tab and change the title at the top of the tab from
Microsoft QuickBASIC to QBASIC and change the Cmd-line to:
A:\QBASIC.EXE /RUN A:\QB&MOUSE.BAS
Check that the Working directory is A:\ and left click Apply and OK.
Double left click the shortcut to start QB&MOUSE.BAS. In the text screen, the mouse cursor range is
restricted to the chess board and the letters below it. In the graphics screen, the mouse limits don't apply
because the mouse cursor must be free to reach the tool bar. Change the font size, shown at the left end of
the graphics screen tool bar, to 10x18 or 12x20.
The program maintains two chess boards: the displayed board and the saved board. At the start, the displayed
board is set with all the pieces for the start of a game and the saved board is blank. At any stage, double
left click anywhere BELOW THE BOARD TO RESTORE the saved board OR double left click anywhere ON THE BOARD TO
SAVE the current board. Double right click closes the program. The time delay in SUB PressClick is about 8/18
of a second to allow you to complete a double click. Alter this to suit yourself.
To set up a puzzle or an example game, first restore the blank board. To put a chess piece on the board,
single left click a yellow letter below the board and then single right click the square or squares where the
piece is to go. Put the required pieces on the board and save it. To move a piece, use drag and drop with
either mouse button. Drop onto a piece of the opposite colour to take it. Save the board at any critical
stage so that you can return to review alternative moves.
On 14 March 2000, Garry Kasparov (White) simultaneously played 30 juniors including Sam Chow of Melbourne
aged 12 (Black) who played 46 moves against the master. Wow! The screen image displays the position after 40
moves. White is in check and is to move. The remaining moves were 41.Kg3 d3 42.Rf6 Rg2+ 43.KXg2 KXh4 44.Rh6+
Bh5 45.g6+ Kg4 46.RXh5. Black resigned. Could you make a better Black move 41?
If you copy QB&MOUSE.BAS and the QBASIC files to another drive, they don't have to go to the same
directory (NB only one copy of QBASIC.EXE and QBASIC.HLP is needed on your hard drives to run all your QBASIC
programs). Make new shortcuts on the desktop or in any other directory. Keep the floppy disk as a
backup.
To modify this program, use the code in QB&MOUSE1 with appropriate values in SUB MouseLimits and you can
add and/or delete GOSUBs in the DO LOOP. The code in QB&MOUSE2 is specific to this application so replace
it with your own subroutines.
Use the code in QB&MOUSE3 unchanged.
Reprinted from the November 2000 issue of PC Update, the
magazine of Melbourne PC User Group, Australia
|