home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / basic / mlib30 / mlibsam3.bas < prev    next >
Encoding:
BASIC Source File  |  1994-02-21  |  7.6 KB  |  186 lines

  1.  DEFINT A-Z
  2.  '============================= MLIBSAM3.BAS ================================
  3.  '                  THIS SAMPLE PROGRAM IS PROVIDED AS IS.
  4.  '
  5.  ' You may modify/use this code in any way you wish, provided that you agree
  6.  ' that Terry Venn has no warranties, obligations or liabilities for any code
  7.  ' contained in this sample program.
  8.  '
  9.  ' MLIBSAM3.BAS is a sample program that demonstrates the following routines:
  10.  '
  11.  ' SetBoundM()      - Confine pointer movement to specified screen area.
  12.  ' InWinM()         - Determines if pointer is in specified area.
  13.  ' Pointer Shapes   - Show multiple pointer shapes from MLIB library.
  14.  '
  15.  ' QB refers to: QuickBasic 4.5
  16.  ' VBDOS refers to: Visual Basic for DOS
  17.  '
  18.  ' To run this sample program from inside the QB environment, start the QB
  19.  ' editor by typing: QB/L MLIBN
  20.  '
  21.  ' To run this sample program from inside the VBDOS environment, start the
  22.  ' editor by typing: VBDOS/L MLIBF
  23.  '
  24.  ' QuickBasic and Visual Basic are trademarks of Microsoft Corporation.
  25.  '===========================================================================
  26.  
  27.  ' $INCLUDE: 'MLIB.BI'                           '
  28.                                                  '
  29. TYPE WindowType                                  '
  30.       x1 AS INTEGER                              '
  31.       y1 AS INTEGER                              '
  32.       x2 AS INTEGER                              '
  33.       y2 AS INTEGER                              '
  34.       wc AS INTEGER'Win color.                   '
  35. END TYPE                                         '
  36.                                                  '
  37. DECLARE SUB InitWin ()                           '
  38. DECLARE SUB CreateWin ()                         '
  39. DECLARE SUB NumberWin ()                         '
  40. DECLARE FUNCTION ActiveWin ()                    '
  41.                                                  '
  42. DIM SHARED Win(1 TO 8) AS WindowType             '
  43. DIM SHARED WinLB%, WinUB%                        '
  44. WinLB% = LBOUND(Win, 1)                          'Set these vars now, so we
  45. WinUB% = UBOUND(Win, 1)                          'only make one call to get
  46.                                                  'upper/lower boundaries.
  47. SCREEN 12: CLS : CALL InitPointer(NumBut%)       '
  48. IF NumBut% = 0 THEN                              '
  49.    SCREEN 0                                      '
  50.    PRINT "No mouse"                              '
  51.    END                                           '
  52. END IF                                           '
  53.                                                  '
  54. CALL GetSpeedM(OldH%, OldV%, OldD%)              'Save speed settings.
  55. CALL SetSpeedM(50, 50, 50)                       'Use our own settings.
  56. CALL SetBoundM(1, 1, 638, 110)                   'Confine pointer to area
  57.                                                  'around windows.
  58. CALL InitWin                                     '
  59. CALL CreateWin                                   '
  60. CALL NumberWin                                   '
  61.                                                  '
  62. LOCATE 10, 1                                     '
  63. PRINT "Clicked in window:"                       '
  64.                                                  '
  65. LOCATE 28, 1                                     '
  66. PRINT "Press any key to end..."                  '
  67. CALL ShowPointer                                 '
  68.                                                  '
  69. DO                                               '
  70.                                                  '
  71.   DO                                             '
  72.                                                  '
  73.      CALL GetButtonM(But%, MX%, MY%)             'Get mouse button status
  74.                                                  'pointer position.
  75.      I% = ActiveWin                              '
  76.      IF I% <> OldI% THEN                         'Check if pointer is in
  77.         SELECT CASE I%                           'one of the windows.
  78.            CASE 1: ARROW0                        'Call a different shape
  79.            CASE 2: HANDV0                        'for each window.
  80.            CASE 3: HOURGLASS0                    'These shapes were created
  81.            CASE 4: PEN0                          'by: ME.EXE(mouse editor)
  82.            CASE 5: MAGNIFYGLASS0                 'CVTASM.EXE(convert-assembly)
  83.            CASE 6: PAINTCUP0                     'assembled(MASM compatible)
  84.            CASE 7: MOUSE0                        'linked to MLIB. ME/CVTASM
  85.            CASE 8: WATCH0                        'included in registered ver.
  86.            CASE ELSE: ARROW1                     'Not in a window, call
  87.         END SELECT                               'default shape.
  88.         OldI% = I%                               '
  89.      END IF                                      '
  90.                                                  '
  91.      IF LEN(INKEY$) THEN                         'Restore speed settings
  92.         CALL SetSpeedM(OldH%, OldV%, OldD%)      'before exiting.
  93.         SCREEN 0: END                            '
  94.      END IF                                      '
  95.                                                  '
  96.   LOOP UNTIL But%                                '
  97.                                                  '
  98.   IF I% THEN                                     'Pointer is in a window.
  99.      x1 = Win(I%).x1                             'do some things and stuff.
  100.      y1 = Win(I%).y1                             '
  101.      x2 = Win(I%).x2                             '
  102.      y2 = Win(I%).y2                             '
  103.      DIM Box(1 TO 1822)                          '
  104.      HidePointer                                 '
  105.      GET (x1, y1)-(x2, y2), Box                  '
  106.      PUT (162, 135), Box, PSET                   '
  107.      ShowPointer                                 '
  108.   END IF                                         '
  109.                                                  '
  110.   WHILE But%                                     'Loop while button is down.
  111.      CALL GetButtonM(But%, MX%, MY%)             '
  112.   WEND                                           '
  113.                                                  '
  114. LOOP                                             '
  115.  
  116. FUNCTION ActiveWin
  117.  
  118. ActiveWin = 0 'Prove otherwise.
  119.  
  120. FOR El = WinLB% TO WinUB%                        'Check first through last
  121.                                                  'Win(?) element, or until
  122.                                                  'a match is made.
  123.    x1 = Win(El).x1 'Easier to read.
  124.    y1 = Win(El).y1
  125.    x2 = Win(El).x2
  126.    y2 = Win(El).y2
  127.  
  128.                                                  'NOTE! InWinM always checks
  129.                                                  'current pointer position.
  130.                                                  'InWinM returns -1,if inside
  131.                                                  'defined area.
  132.    IF InWinM(x1, y1, x2, y2) THEN                'Pointer is inside Win(?),
  133.                                                  'return element number.
  134.       ActiveWin = El
  135.       EXIT FOR
  136.      
  137.    END IF
  138.  
  139. NEXT El
  140.  
  141. END FUNCTION
  142.  
  143. SUB CreateWin
  144. 'Draw 8 windows.
  145.  
  146. FOR Num% = LBOUND(Win, 1) TO UBOUND(Win, 1)
  147.  
  148. LINE (Win(Num%).x1, Win(Num%).y1)-(Win(Num%).x2, Win(Num%).y2), Win(Num%).wc, B
  149. LINE (Win(Num%).x1 + 2, Win(Num%).y1 + 2)-(Win(Num%).x2 - 2, Win(Num%).y2 - 2), Win(Num%).wc, BF
  150.  
  151. NEXT Num%
  152.  
  153. END SUB
  154.  
  155. SUB InitWin
  156. 'Initialize Win() array.
  157.  
  158. Y = 0
  159.  
  160. FOR X = 1 TO 640 STEP 80
  161.   
  162.    Y = Y + 1
  163.   
  164.    Win(Y).x1 = X
  165.    Win(Y).y1 = 10
  166.    Win(Y).x2 = X + 72
  167.    Win(Y).y2 = 100
  168.    Win(Y).wc = Y   'win color.
  169.  
  170. NEXT
  171.  
  172. END SUB
  173.  
  174. SUB NumberWin
  175. 'Number each window.
  176.  
  177. FOR X = 1 TO 80 STEP 10
  178.  
  179.    LOCATE 2, X + 3
  180.    PRINT X \ 10 + 1
  181.  
  182. NEXT
  183.  
  184. END SUB
  185.  
  186.