home *** CD-ROM | disk | FTP | other *** search
- '*******************************************************************
- '* MOUSEDEM.BAS *
- '* By Kyle Sparks, Microsoft Corporation, 1988 *
- '* *
- '* Demonstrates calling mouse functions using a subprogram *
- '* named MouseDriver. This subprogram uses CALL INTERRUPT *
- '* to access the mouse driver. *
- '* *
- '* To load QB.QLB into memory with QuickBASIC, type: QB /L QB.QLB *
- '*******************************************************************
-
- DEFINT A-Z
-
- '------------------------------ Define Types --------------------------------
-
- TYPE Register 'for CALL INTERRUPT
- ax AS INTEGER
- bx AS INTEGER
- cx AS INTEGER
- dx AS INTEGER
- bp AS INTEGER
- si AS INTEGER
- di AS INTEGER
- flags AS INTEGER
- END TYPE
-
- '--------------------- Declare Procedures and Functions ---------------------
-
- DECLARE FUNCTION MouseDoubleClick (Delay%, Button%, m3%, m4%)
-
- ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- DECLARE SUB Interrupt (intnum AS INTEGER, inreg AS Register, outreg AS Register)
- DECLARE SUB MakeBox (Left%, Top%, Right%, Bottom%, Border%)
- DECLARE SUB MouseDriver (m0%, m1%, m2%, m3%)
- DECLARE SUB MouseConfineCursor (Left%, Top%, Right%, Bottom%)
- DECLARE SUB MouseDefinePerimeter ()
- DECLARE SUB MouseInit ()
- DECLARE SUB MouseOn ()
- DECLARE SUB MouseOff ()
- DECLARE SUB MouseSetHardCursor ()
- DECLARE SUB MouseSetSoftCursor ()
- DECLARE SUB MouseShowCoord ()
- DECLARE SUB MoveToScreen (x1%, y1%, x2%, y2%, Buffer())
- DECLARE SUB MoveFromScreen (x1%, y1%, x2%, y2%, Buffer())
- DECLARE SUB PopDown (OldY%)
- DECLARE SUB PopUp (OldY%)
-
- '--------------------------- Main Control Program ---------------------------
-
- 'BEGIN
-
- CLS
- PRINT STRING$(80 * 25, 176);
-
- PopUp OldY
- MouseInit
- MouseShowCoord
- MouseSetHardCursor
- MouseSetSoftCursor
- MouseDefinePerimeter
- PopDown OldY
-
- END
-
- SUB MakeBox (Left, Top, Right, Bottom, Border)
- '----------------------------------------------------------------------------
- ' Procedure MakeBox draws a box on the screen starting at Top, Left and
- ' ending at Bottom, Right using either no border, or a single or double-
- ' line border based on the value of Border.
- '----------------------------------------------------------------------------
-
- SELECT CASE Border
- CASE 1
- VertLine$ = CHR$(179)
- HorizLine$ = CHR$(196)
- UpLeft$ = CHR$(218)
- UpRight$ = CHR$(191)
- LowLeft$ = CHR$(192)
- LowRight$ = CHR$(217)
-
- CASE 2
- VertLine$ = CHR$(186)
- HorizLine$ = CHR$(205)
- UpLeft$ = CHR$(201)
- UpRight$ = CHR$(187)
- LowLeft$ = CHR$(200)
- LowRight$ = CHR$(188)
-
- CASE ELSE
- VertLine$ = CHR$(32)
- HorizLine$ = CHR$(32)
- UpLeft$ = CHR$(32)
- UpRight$ = CHR$(32)
- LowLeft$ = CHR$(32)
- LowRight$ = CHR$(32)
-
- END SELECT
-
- LOCATE Top, Left
- PRINT UpLeft$; STRING$((Right - Left) - 1, HorizLine$); UpRight$;
- FOR Y = Top + 1 TO Bottom - 1
- LOCATE Y, Left
- PRINT VertLine$; SPACE$((Right - Left) - 1); VertLine$;
- NEXT Y
- LOCATE Bottom, Left
- PRINT LowLeft$; STRING$((Right - Left) - 1, HorizLine$); LowRight$;
-
- END SUB
-
- SUB MouseConfineCursor (Left, Top, Right, Bottom)
- '----------------------------------------------------------------------------
- ' Procedure MouseConfineCursor makes mouse function calls to confine the
- ' mouse cursor to the specified area.
- '----------------------------------------------------------------------------
-
- Border = 1
-
- m1 = 7 'Mouse Function 7, Set Minimum and Maximum
- 'Horizontal Cursor Position
- m3 = (Left - 1) * 8 'Minimum
- m4 = (Right - 1) * 8 'Maximum
- MouseDriver m1, m2, m3, m4
-
- m1 = 8 'Mouse Function 8, Set Minimum and Maximum
- 'Vertical Cursor Position
- m3 = (Top - 1) * 8 'Minimum
- m4 = (Bottom - 1) * 8 'Maximum
- MouseDriver m1, m2, m3, m4
-
- END SUB
-
- SUB MouseDefinePerimeter
- '----------------------------------------------------------------------------
- ' Procedure MouseDefinePerimeter defines the maximum and mininum vertical
- ' and horizontal boundaries for the mouse cursor, and then passes them
- ' to MouseConfineCursor.
- '----------------------------------------------------------------------------
-
- DIM Buffer(4000), Buffer2(4000)
-
- MoveFromScreen 17, 6, 60, 16, Buffer()
-
- COLOR 7, 0 'FOREGROUND = white, BACKGROUND = black
-
- ulc = 17
- ulr = 6
- llc = 60
- llr = 16
- Border = 2
-
- MakeBox ulc, ulr, llc, llr, Border
-
- LOCATE ulr + 2, ulc + 3: PRINT "Select boundaries for mouse cursor."
- LOCATE 23, 1
-
- LOCATE ulr + 4, ulc + 3
- PRINT "Select the upper-left corner with";
- LOCATE ulr + 5, ulc + 3
- PRINT "mouse, and then press the button."
-
- MouseOn
-
- m1 = 3
- m2 = 0
-
- WHILE m2 = 0
- MouseDriver m1, m2, m3, m4
- WEND
- WHILE m2 > 0
- MouseDriver m1, m2, m3, m4
- WEND
-
- MouseOff
-
- Top = m4 \ 8
- Left = m3 \ 8
-
- LOCATE ulr + 4, ulc + 3
- PRINT "Select the lower-right corner with";
- LOCATE ulr + 5, ulc + 3
- PRINT "mouse, and then press the button."
-
- MouseOn
-
- m1 = 3
- m2 = 0
-
- WHILE m2 = 0
- MouseDriver m1, m2, m3, m4
- WEND
- WHILE m2 > 0
- MouseDriver m1, m2, m3, m4
- WEND
-
- MouseOff
-
- Bottom = m4 \ 8
- Right = m3 \ 8
- Border = 1
-
- MoveToScreen 17, 6, 60, 16, Buffer()
- MoveFromScreen Left + 1, Top + 1, Right + 1, Bottom + 1, Buffer()
- MakeBox Left + 1, Top + 1, Right + 1, Bottom + 1, Border
- MouseConfineCursor Left + 1, Top + 1, Right + 1, Bottom + 1
-
- MoveFromScreen 1, 1, 80, 1, Buffer2()
-
- COLOR 0, 7
- LOCATE 1, 1
- PRINT SPACE$(19); "/> Press left button twice to exit... <."; SPACE$(19);
- COLOR 7, 0
- MouseOn
-
- Button = 0 'Check left button
- WaitForClick = 1 'Wait 1 second for double-click
-
- WHILE X = 0
- X = MouseDoubleClick(WaitForClick, Button, ClickX, ClickY)
- WEND
-
- MouseOff
-
- MoveToScreen 1, 1, 80, 1, Buffer2()
- MoveToScreen Left + 1, Top + 1, Right + 1, Bottom + 1, Buffer()
-
- END SUB
-
- FUNCTION MouseDoubleClick (Delay, Button, m3, m4)
- '----------------------------------------------------------------------------
- ' Function MouseDoubleClick returns a zero if the mouse button specified by
- ' Button has not been double-clicked within the time specified by Delay, or
- ' a one if it has. Button is either 0 (Left) or 1 (Right).
- '
- ' RETURNS:
- '
- ' m1 = button status. 0 = No buttons pressed
- ' 1 = Left button pressed
- ' 2 = Right button pressed
- ' 3 = Both buttons pressed
- '
- ' m2 = Number of button presses on specified button
- ' m3 = Horizontal cursor position at last button press.
- ' m4 = Vertical cursor position at last button press.
- '
- '----------------------------------------------------------------------------
-
- m1 = 5 'Mouse Function 5, Get Button Press Information
- m2 = Button 'Button to check
- MouseDriver m1, m2, m3, m4
-
- WaitForClick& = TIMER + Delay
- WHILE TIMER < WaitForClick&: WEND
-
- m1 = 5 'Mouse Function 5, Get Button Press Information
- m2 = Button
- MouseDriver m1, m2, m3, m4
-
- IF m2 > 1 THEN MouseDoubleClick = 1 ELSE MouseDoubleClick = 0
-
- END FUNCTION
-
- SUB MouseDriver (m0, m1, m2, m3) STATIC
- '----------------------------------------------------------------------------
- ' Procedure MouseDriver uses Interrupt 51 to invoke mouse functions in the
- ' Microsoft mouse driver. NOTE: ALL parameters to this procedure MUST
- ' be of type INTEGER.
- '----------------------------------------------------------------------------
-
- DIM regs AS Register
-
- regs.ax = m0
- regs.bx = m1
- regs.cx = m2
- regs.dx = m3
-
- Interrupt 51, regs, regs
-
- m0 = regs.ax
- m1 = regs.bx
- m2 = regs.cx
- m3 = regs.dx
-
- END SUB
-
- SUB MouseInit
- '----------------------------------------------------------------------------
- ' Procedure MouseInit initializes the mouse and detects whether
- ' the Microsoft mouse driver is installed.
- '----------------------------------------------------------------------------
-
- DIM Buffer(4000)
-
- MoveFromScreen 17, 6, 60, 13, Buffer()
-
- COLOR 7, 0 'FOREGROUND = white, BACKGROUND = black
-
- ulc = 17
- ulr = 6
- llc = 60
- llr = 13
- Border = 2
-
- MakeBox ulc, ulr, llc, llr, Border
-
- m1 = 0
- MouseDriver m1, m2, m3, m4
-
- IF NOT m1 THEN
- LOCATE 8, 25
- PRINT "Microsoft Mouse not installed."
- MoveToScreen 17, 6, 60, 12, Buffer()
- t = TIMER + 2
- WHILE TIMER < t: WEND
- END
- ELSE
- LOCATE 8, 25
- PRINT "Microsoft Mouse found."
- LOCATE 9, 25
- PRINT "Buttons:"; m2
- END IF
-
- WHILE INKEY$ <> CHR$(13): WEND
-
- MoveToScreen 17, 6, 60, 13, Buffer()
-
- END SUB
-
- SUB MouseOff
- '----------------------------------------------------------------------------
- ' Procedure MouseOff turns the mouse cursor off. (Mouse Function 2)
- '----------------------------------------------------------------------------
-
- m1 = 2
- MouseDriver m1, m2, m3, m4
-
- END SUB
-
- SUB MouseOn
- '----------------------------------------------------------------------------
- ' Procedure MouseOn turns the mouse cursor on. (Mouse Function 1)
- '----------------------------------------------------------------------------
-
- m1 = 1
- MouseDriver m1, m2, m3, m4
-
- END SUB
-
- SUB MouseSetHardCursor
- '----------------------------------------------------------------------------
- ' Procedure MouseSetHardCursor selects the hardware text cursor to use
- ' for the mouse.
- '----------------------------------------------------------------------------
-
- DIM Buffer(4000)
-
- MoveFromScreen 17, 6, 60, 13, Buffer()
-
- COLOR 0, 7 'FOREGROUND = black, BACKGROUND = white
-
- ulc = 17
- ulr = 6
- llc = 60
- llr = 13
- Border = 1
-
- MakeBox ulc, ulr, llc, llr, Border
-
- LOCATE ulr + 2, ulc + 1: PRINT " This procedure uses the hardware "
- LOCATE ulr + 3, ulc + 1: PRINT " text cursor as the mouse cursor, "
- LOCATE ulr + 4, ulc + 1: PRINT " causing a blinking mouse cursor. "
- LOCATE ulr + 6, ulc + 1: PRINT " <Press button to continue> "
-
- m1 = 10 'Mouse Function 10, Set Text Cursor
- m2 = 1 'Select hardware text cursor
- m3 = 2 'Top scan line of text cursor
- m4 = 7 'Bottom scan line of text cursor
-
- MouseDriver m1, m2, m3, m4
-
- MouseOn
-
- m1 = 3 'Mouse Function 3, Get Button Status and
- 'Mouse Position
- m2 = 0
-
- WHILE m2 = 0
- MouseDriver m1, m2, m3, m4
- WEND
-
- MoveToScreen 17, 6, 60, 13, Buffer()
-
- MouseOn
-
- LOCATE , , 1, 6, 7
- LOCATE , , 0
-
- MouseOff
-
- END SUB
-
- SUB MouseSetSoftCursor
- '----------------------------------------------------------------------------
- ' Procedure MouseSetSoftCursor selects the hardware text cursor to use
- ' for the mouse.
- '
- ' m3 = screen mask
- ' m4 = cursor mask
- '
- ' ■ The screen mask determines which of the character's attributes
- ' are preserved.
- '
- ' * The cursor mask determines how these attributes are changed to
- ' yield the cursor.
- '
- ' The bit values for the screen and cursor mask are:
- '
- ' BIT PURPOSE
- ' ------- ----------------------
- ' 15 1 = blinking, 0 = normal
- ' 12-14 3 byte foreground color (000 = 0, 111 = 7)
- ' 11 1 = high intensity, 0 = normal intensity
- ' 08-10 3 byte background color (000 = 0, 111 = 7)
- ' 00-07 8 byte ASCII value of character for cursor
- ' (00000000 = 0, 11111111 = 255 or CHR$(255))
- '
- ' The default values are indicated below. They are the most useful values
- ' for this function.
- '----------------------------------------------------------------------------
-
- m1 = 10 'Mouse Function 10, Set Text Cursor
- m2 = 0 'Select software mouse cursor
-
- ' 1 0
- ' BIT 5432 1098 7654 3210
- ' ----|----|----|----
- m3 = &HFFFF 'Screen mask: Binary = 1111 1111 1111 1111
- ' Hex = F F F F
- ' Decimal = 32767 (2^15 + 2^14 +...+ 2^1 + 2^0)
-
- m4 = &H7700 'Cursor mask: Binary = 0111 0111 0000 0000
- ' Hex = 7 7 0 0
- ' Decimal = 30464 (2^14 + 2^13 + 2^12 +2^10 + 2^9 + 2^8)
-
- MouseDriver m1, m2, m3, m4
-
- END SUB
-
- SUB MouseShowCoord
- '----------------------------------------------------------------------------
- ' Procedure MouseShowCoord shows the mouse coordinates and button status
- ' in a window on the screen.
- '----------------------------------------------------------------------------
-
- DIM Buffer(4000)
-
- MoveFromScreen 17, 6, 60, 13, Buffer()
-
- COLOR 7, 0 'FOREGROUND = white, BACKGROUND = black
-
- ulc = 17
- ulr = 6
- llc = 60
- llr = 13
- Border = 2
-
- MakeBox ulc, ulr, llc, llr, Border
-
- LOCATE ulr + 6, ulc + 1: PRINT " <Use Mouse or press Enter> "
-
- LOCATE 7, 19
- PRINT "Show Mouse Coordinates and Button Status"
- LOCATE 9, 25
- PRINT "Mouse X: Button 1:"
- LOCATE 10, 25
- PRINT "Mouse Y: Button 2:"
-
- MouseOn
-
- m1 = 3 'Mouse function 3, Get Button Status and Mouse Position
-
- WHILE X$ <> CHR$(13)
- X$ = INKEY$
- MouseDriver m1, m2, m3, m4
- LOCATE 9, 33
- PRINT m3 \ 8
- LOCATE 10, 33
- PRINT m4 \ 8
- LOCATE 9, 50
- IF (m2 AND 1) = 1 OR m2 = 3 THEN PRINT "Down" ELSE PRINT "Up "
- LOCATE 10, 50
- IF (m2 AND 2) = 2 OR m2 = 3 THEN PRINT "Down" ELSE PRINT "Up "
- WEND
-
- MouseOff
-
- MoveToScreen 17, 6, 60, 13, Buffer()
-
- END SUB
-
- SUB MoveFromScreen (x1%, y1%, x2%, y2%, Buffer() AS INTEGER) STATIC
- '----------------------------------------------------------------------------
- ' Procedure MoveFromScreen will copy a section of screen RAM.
- '----------------------------------------------------------------------------
-
- DEF SEG = 0
-
- SELECT CASE PEEK(&H449) 'Figure out what video mode is being used
- CASE 0 TO 3
- display = &HB800 'CGA and EGA text modes
- CASE 7
- display = &HB000 'Monochrome text mode
- CASE ELSE
- CLS 'Not a text mode, or not a compatible card
- EXIT SUB
- END SELECT
-
- DEF SEG = display 'Define the segment to be the display memory
-
- FOR XPeek = (x1% - 1) * 2 TO ((x2% - 1) * 2) + 1
- FOR YPeek = y1% - 1 TO y2% - 1
- Buffer((YPeek * 160) + XPeek) = PEEK((YPeek * 160) + XPeek)
- NEXT YPeek
- NEXT XPeek
-
- DEF SEG 'Reset segment pointer
-
- END SUB
-
- SUB MoveToScreen (x1%, y1%, x2%, y2%, Buffer() AS INTEGER) STATIC
- '----------------------------------------------------------------------------
- ' Procedure MoveToScreen will replace the copied screen RAM.
- '----------------------------------------------------------------------------
-
- DEF SEG = 0
-
- SELECT CASE PEEK(&H449) 'Figure out what video mode is being used
- CASE 0 TO 3
- display = &HB800 'CGA and EGA text modes
- CASE 7
- display = &HB000 'Monochrome text mode
- CASE ELSE
- CLS 'Not a text mode, or not a compatible card
- EXIT SUB
- END SELECT
-
- DEF SEG = display 'Define the segment to be the display memory
-
- FOR XPeek = (x1% - 1) * 2 TO ((x2% - 1) * 2) + 1
- FOR YPeek = y1% - 1 TO y2% - 1
- POKE ((YPeek * 160) + XPeek), Buffer((YPeek * 160) + XPeek)
- NEXT YPeek
- NEXT XPeek
-
- DEF SEG 'Reset segment pointer
-
- END SUB
-
- SUB PopDown (OldY)
- '----------------------------------------------------------------------------
- ' Procedure PopDown wraps the program up with a final message, and then
- ' waits for a double-click in the 'Okay' box.
- '----------------------------------------------------------------------------
-
- DIM Buffer(4000)
-
- MoveFromScreen 17, 6, 60, 17, Buffer()
- MouseConfineCursor 18, 7, 59, 16
-
- COLOR 0, 7 'FOREGROUND = black, BACKGROUND = white
-
- ulc = 17
- ulr = 6
- llc = 60
- llr = 17
- Border = 2
-
- MakeBox ulc, ulr, llc, llr, Border
-
- LOCATE ulr + 2, ulc + 1: PRINT " This is the end of this demonstration. "
- LOCATE ulr + 3, ulc + 1: PRINT " For more information on these and "
- LOCATE ulr + 4, ulc + 1: PRINT " other mouse functions, please see The "
- LOCATE ulr + 5, ulc + 1: PRINT " Microsoft Mouse Programmer's Reference."
- LOCATE ulr + 6, ulc + 1: PRINT " "
- LOCATE ulr + 7, ulc + 1: PRINT " "
- LOCATE ulr + 8, ulc + 1: PRINT " ┌────────────┐ "
- LOCATE ulr + 9, ulc + 1: PRINT " Double-click to end. │ Okay │ "
- LOCATE ulr + 10, ulc + 1: PRINT " └────────────┘ "
-
- MouseOn
-
- Button = 0 'Check Left button
- WaitForClick = 1 'Wait 1 second for double-click
-
- WHILE ButtonCheck = 0 OR ((X < 40 OR X > 53) OR (Y < 13 OR Y > 15))
- ButtonCheck = MouseDoubleClick(WaitForClick, Button, ClickX, ClickY)
- X = ClickX \ 8
- Y = ClickY \ 8
- WEND
-
- MouseOff
-
- MoveToScreen 17, 6, 60, 17, Buffer()
-
- LOCATE OldY, , 0
- COLOR 7, 0
-
- END SUB
-
- SUB PopUp (OldY)
- '----------------------------------------------------------------------------
- ' Procedure Popup displays an introductory message on the screen.
- '----------------------------------------------------------------------------
-
- OldY = CSRLIN 'Memorize old Y text cursor positon
-
- DIM Buffer(4000)
-
- MoveFromScreen 17, 6, 60, 17, Buffer()
-
- COLOR 0, 7 'FOREGROUND = black, BACKGROUND = white
-
- ulc = 17
- ulr = 6
- llc = 60
- llr = 17
- Border = 2
-
- MakeBox ulc, ulr, llc, llr, Border
-
- LOCATE ulr + 2, ulc + 1: PRINT " Calling the Microsoft Mouse from "
- LOCATE ulr + 3, ulc + 1: PRINT " QuickBASIC Version 4 "
- LOCATE ulr + 5, ulc + 1: PRINT " Samples and Demonstration "
- LOCATE ulr + 6, ulc + 1: PRINT " Programs "
- LOCATE ulr + 8, ulc + 1: PRINT " By Kyle Sparks, Microsoft Corp., 1988 "
- LOCATE ulr + 10, ulc + 1: PRINT " <press Enter> "
- WHILE INKEY$ <> CHR$(13): WEND
- LOCATE 23, 1
-
- MoveToScreen 17, 6, 60, 17, Buffer()
-
- END SUB
-