BBS: Inland Empire Archive Date: 11-24-92 (15:14) Number: 354 From: TONY ELLIOTT Refer#: NONE To: STEVEN MORGAN Recvd: NO Subj: Re: Mouse routines Conf: (2) Quik_Bas
Steven,
SM> I downloaded QBnws... Your Mouse Program was Great! It was well
SM> documented and you examples were very helpful. I had no problems with
SM> your library, you made it extremely easy to establish procedures for
SM> the mouse functions.
<blush> Thanks!
SM> Could you please leave a short example as to how I could create an
SM> event that activates when a button, row, colunm has been met and then
SM> how I can co.nect it to call a procedure.
Sure. You can do it a couple of different ways. If you know a little
about MASM, you could modify the assembly code to accept an array of
coordinates (perhaps in the MouseSetEvent routine). When the specified
mouse event occurs (left button press), compare the pointer position
with your array of corrdinates. If there's a match, THEN call the
SETUEVENT routine.
Or... you could leave the mouse ASM code as-is and define an BASIC
procedure that executes each time the left button is pressed. In that
subroutine, you could check your coordinate array and see if you have a
match. The example program included with the article already sets up a
UEVENT trap for a right-button click. Just expand the subroutine to
include checking one or more sets of coordinates. Here's an example
using the mouse routines from QBNews:
DEFINT A-Z
REM $INCLUDE: 'MOUSE.BI'
TYPE Coordinates 'Structure for our "hot spot"
TopRow AS INTEGER ' coordinates.
LeftCol AS INTEGER
BottomRow AS INTEGER
RightCol AS INTEGER
END TYPE
'The following routine resets the mouse and returns the number
'of buttons.
Buttons% = MouseReset%
IF Buttons = 0 THEN
PRINT "No mouse present."
END
END IF
CLS 'Display some "buttons"
LOCATE 10, 1
PRINT " ************ ************ ************"
PRINT " * Button 1 * * Button 2 * * Finished *"
PRINT " ************ ************ ************"
DIM H(1 TO 3) AS Coordinates
FOR Z% = 1 TO 3 'Set up our coordinate array
H(Z%).TopRow = 10 ' that defines these three
H(Z%).LeftCol = (Z% - 1) * 16 + 5 ' "buttons"
H(Z%).BottomRow = 12
H(Z%).RightCol = H(Z%).LeftCol + 11
NEXT
CALL MousePointerOn 'Turn on mouse pointer
CALL MouseSetEvent(2) '2 - Left button press
ON UEVENT GOSUB MouseEventHandler 'Point to an event hander
UEVENT ON 'Turn on event trapping.
DO
A$ = INKEY$ 'Wait for a key
EventCheckLabel: '/W will cause check for
LOOP UNTIL LEN(A$) OR Finished% ' events here.
UEVENT OFF 'Turn off event trapping
CALL MouseCancelEvent 'Turn our handler off.
CALL MousePointerOff
END
MouseEventHandler:
'This subroutine used in conjunction with the MouseSetEvent and
'UEVENT demonstration. This routine is called only when the
'defined mouse event occurs.
CALL MouseGetEventInfo(EventFlag%, Lb%, Rb%, Cb%, Row%, Column%)
CALL MousePointerOff 'To prevent mouse droppings
FOR Z% = 1 TO 3
IF Row% >= H(Z%).TopRow AND Row% <= H(Z%).BottomRow THEN
IF Column% >= H(Z%).LeftCol AND Column% <= H(Z%).RightCol THEN
'We found one. Exit the loop, leaving Z% indicating the
' "button" that was clicked on.
EXIT FOR
END IF
END IF
NEXT
LOCATE 15, 10
IF Z% <= 3 THEN 'If a valid button
BEEP
PRINT "Click on button"; Z%
ELSE
PRINT "Click at"; Row; ","; Column%; " " 'Erase last click info
END IF
CALL MousePointerOn 'Back on
RETURN
--- Blue Wave/Max v2.10 [NR]
* Origin: Oakland BBS - McDonough, GA - (404) 954-0071 (1:133/706.0)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET