[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
MSDOS » thunks » QBasicFAQ » Calculating and Validating NMEA Checksums » CppBuilder » CMOS_C » The GPRMC Sentence » TurboCpp » BeginnersGuideToCurl » Curl Content Language » QbasicFAQ_Mouse
How do I use the mouse in my QBasic programs?


Back to QBasic FAQ Main Page.

Suffice to say, that there are several good ways to get the mouse to work in your QB program. Here is one way of doing it:

' Mouse routines...
'
' Revised by UnderWARE Labs(1996)
' (These routines have been around for quite a while now).
'
' Some notes about use...
' Cursor placement and coordinate positions are different depending 
' on the current screen mode.
' "GetMouse"  returns the x and y coordinates of the mouse driver, 
' NOT the actual screen coordinates.  These numbers are then corrected, 
' for the screen mode chosen.  (See the SUB GetMouse).
'
' The x coordinate of the mousedriver is always 0 thru 639, and the y
' coordinate could be:  0-199, 0-349, or 0-479, depending on the mode.
'
' You will need to change this by REM-ing out and selecting the 
' correct,lines in each of the affected SUB's, so the SUB's report the 
' coodinates,that YOU will use.
'
' FOR QUICK BASIC USERS ONLY...
' These revised mouse routines will work with QuickBasic and the 
' QB4.5's Quick Libraries.    Use with "MOUSE.QLB".
'
' Load Quick Basic using the command line parameters: 
' "QB /L MOUSE.QLB"
' To also load this program at the same time: 
' "QB /L MOUSE.QLB MOUSE-IT.BAS"
'--------------------------------------------------------------------
DECLARE SUB Getmouse (lb%, rb%, xMouse%, yMouse%)       'Mouse SUBs:
DECLARE SUB Limits (x1%, y1%, x2%, y2%)
DECLARE SUB LocateCursor (x%, y%)
DECLARE SUB CursorOff ()
DECLARE SUB MouseDriver (ax%, bx%, cx%, dx%)
DECLARE SUB CursorOn ()
DECLARE FUNCTION Initialize% ()
'____________________________________________________________________
'~~~~~~~~~~~~~ Mouse Initialization ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim Mouse$                                  'Needed only once.
  Mouse$ = Space$(57)
  For i% = 1 To 57
        READ a$
        H$ = Chr$(Val("&H" + a$))
        Mid$(Mouse$, i%, 1) = H$
  Next i%
DATA 55,89,E5,8B,5E,0C,8B,07,50,8B,5E,0A,8B,07,50,8B
DATA 5E,08,8B,0F,8B,5E,06,8B,17,5B,58,1E,07,CD,33,53       'MouseDATA
DATA 8B,5E,0C,89,07,58,8B,5E,0A,89,07,8B,5E,08,89,0F
DATA 8B,5E,06,89,17,5D,CA,08,00
'----------------------------------------------------------------
Cls
        ms% = Initialize%
        If Not ms% Then                      ' also needed only once.
          Print "Mouse not found"
          End
        End If
'-----------------------------------------------------------------
' Main program start... and example usage...
'-----------------------------------------------------------------
Screen 0
Color 1, 1                                       ' set screen color
Cls                                              ' clear screen
Color 0, 7                                       ' set button color
LOCATE 10, 30: Print " C L I C K   H E R E "     ' print text
Color 0, 1                                       ' shadow color
LOCATE 11, 31: Print "ßßßßßßßßßßßßßßßßßßßßß"     ' shadow
LOCATE 10, 51: Print "Ü"                         ' shadow too.
LOCATE 23, 29: Print "Press [ESC] to quit program." ' Print this too.
Color 14
LOCATE 3, 30: Print "M O U S E - I T . B A S"
Color 12
LOCATE 4, 8: Print "Easy to use mousing routines for QBasic 4.5"
Color 7                                            ' set new text color
CursorOn                                           ' Turn mouse on
 Do While INKEY$ = ""                              ' start a loop
   Getmouse lb%, rb%, x%, y%                       ' Get the mouse info
                                                   ' at each loop pass.
   LOCATE 1, 1: Print "X ="; x%, ; "Y = "; y%; ""  ' Print mouse info
  
   If lb% = -1 Then                            'If left button clicks,
        LOCATE 2, 1: Print " Left  Button Pressed." '    print it.
   End If                                           '
                                                    '
   If rb% = -1 Then                           'If right button clicks,
        LOCATE 2, 1: Print " Right Button Pressed." '    prnt it.
   End If                                           '
   If lb% = -1 And rb%= -1 Then               'If both are pressed,
        LOCATE 2, 1: Print " BOTH Buttons Pressed." '    prnt it.
        While lb% = -1 And rb%= -1
        Getmouse lb%, rb%, x%, y%
        Wend
   End If
   If lb% <> -1 And rb% <> -1 Then     'If both buttons AREN'T clicked, 
        LOCATE 2, 1: Print "                      " ' print blank.
   End If                                           
   If lb% = -1 Then                              'If left buton clicks,
        If y% = 10 And x% > 29 And x% < 51 Then  'If the coordinates 
            GoSub ClickTheButton                 'match,  Gosub below
        End If                                   
        If y% = 23 And x% > 34 And x% < 40 Then
           CursorOff
           LOCATE 23, 35
           Color 15, 0
           Print "[ESC]"
           Exit Do
        End If
   End If                                           '
 Loop                                                 ' Loop back
End                                                   ' END
'---------------------------------------------------------
' a GOSUB routine (not a SUB module or SUB routine)
'---------------------------------------------------------
ClickTheButton:
CursorOff
Color 0, 1
LOCATE 10, 30: Print " "                           ' Cover old "button",
LOCATE 11, 31: Print "                     "       '   and shadow
Color 0, 7                                         ' Make new button
LOCATE 10, 31: Print " C L I C K   H E R E "       '
Do While lb% = -1            'Loop while left button is still pressed...
   Getmouse lb%, rb%, x%, y% 'Get mouse info. (Check that left button).
Loop
Color 0, 7                                      ' set back button color
LOCATE 10, 30: Print " C L I C K   H E R E "    ' print text
Color 0, 1                                      ' shadow color
LOCATE 11, 31: Print "ßßßßßßßßßßßßßßßßßßßßß"    ' shadow
LOCATE 10, 51: Print "Ü"                        ' shadow too.
Color 7                                         ' set new text color
CursorOn                                        ' Turn mouse on
Return                             ' Return back to main.


last edited (December 9, 2002) by KDivad Leahcim, Number of views: 4725, Current Rev: 2 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Site Management by Lars Hagelin at Kontantkort.se.