home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / rodent.zip / RODENT.DOC < prev    next >
Text File  |  1988-09-07  |  5KB  |  162 lines

  1. Adapted from an article in "The Linker" the monthly
  2. newsletter of the Professional Association of Database
  3. Developers,
  4. June 1988
  5. ---------------------------------------------------------
  6.  
  7. Clipper developers can use UDF's created in Assembler to
  8. directly interrogate the mouse driver. There are numerous
  9. advantages and disadvantages to this approach - the key
  10. disadvantage is that the developer must constantly call the
  11. mouse driver to determine the status of the mouse. This
  12. means that the developer cannot rely on any "wait state"
  13. input (accept, input, read, wait, ...) if they wish to use
  14. the mouse as an alternative to the keyboard at the same
  15. time. The structure of the most simple code changes from:
  16.  
  17. *** Sample routine to get input without mouse
  18. accept to string
  19. * end
  20.  
  21. to:
  22.  
  23. *** Sample routine to get input with the mouse
  24. *** demonstration purposes only
  25. *** mrow() returns current mouse row as integer
  26. *** mcol() returns current mouse column as integer
  27. *** mbutleft() returns .T. if left button is pressed
  28. * initialize string
  29. string = ""
  30. do while .T.
  31.      x = 0          && clear value for key press
  32.      do case
  33.      * test mouse
  34.      case mrow() = 10 .and. mcol() = 20 .and. mbutleft()
  35.           string = "First Line"
  36.           exit
  37.      case mrow() = 12 .and. mcol() = 20 .and. mbutleft()
  38.           string = "Second Line"
  39.           exit
  40.      otherwise
  41.           x = inkey()
  42.      endcase
  43.      if x = 13
  44.           * enter pressed
  45.           exit
  46.      endif
  47.      if x > 0
  48.           * key pressed, build string
  49.           string = string+chr(x)
  50.      endif
  51. enddo
  52. * end
  53.  
  54. As you can see, the code modifications required to
  55. incorporate the mouse into your applications is no trivial
  56. undertaking. The inability to use the mouse in "wait-state"
  57. input may make it's use, in other than the keyboard
  58. emulation mode, impractical for many applications (if all
  59. you require is keyboard emulation, see some of the other
  60. packages available on the market).
  61.  
  62. Now that you've seen what is involved in adding mouse
  63. support to your programs, lets examine the functions
  64. required for basic mouse support. The object file RODENT.OBJ
  65. contains 11 functions to support low level calls to any
  66. Microsoft compatible mouse driver (including IBM, Logitech
  67. and most others). It will support applications in the 25
  68. row, 80 column text mode only.
  69.  
  70. ISMOUSE() - Returns .T. if mouse driver is present
  71. MRESET()  - Resets the mouse driver, returns # of buttons on
  72.           mouse
  73. MSHOW()   - Display mouse cursor
  74. MHIDE()   - Hides the mouse cursor
  75. MROW()    - Returns current mouse cursor row (int)
  76. MCOL()    - Returns current mouse cursor column (int)
  77. MLEFT()   - Returns .T. if left mouse button is pressed
  78. MRIGHT()  - Returns .T. if right mouse button is pressed
  79. MCENTER() - Returns .T. if center mouse button is pressed
  80. MTOPOS(<row>,<col>) - Moves mouse cursor to position
  81.           specified by row, col
  82. MAREA(<uprow>,<upcol>,<lwrrow>,<lwrcol>)     - Limits mouse
  83.           cursor movement to area specified by uprow, upcol,
  84.           lowerrow, lowercol
  85.  
  86. None of the functions do any error checking, the developer
  87. must insure the values passed to MTOPOS and MAREA are valid.
  88. If there is no center button the mouse, the result of
  89. calling mcenter will depend upon the driver loaded
  90. (Microsoft's drivers will return .F.).
  91.  
  92. Using the above functions, we can monitor the mouse's
  93. movement and button status, enabling the creation of pop-up
  94. boxes such as:
  95.  
  96. *** POPUPMSG
  97. *** Displays message on screen,
  98. *** wait for button release in message box
  99. parameters popmsg
  100. save screen
  101. * clear message area in reverse
  102. set color to N/W
  103. @ 10,20 clear to 15,59
  104. @ 10,20 to 15,59 double
  105. @ 11,25 say popmsg
  106. @ 12,25 to 14,54 single
  107. @ 12,28 say "Click Mouse Here to Go On"
  108.  
  109. * set button flag
  110. butdown = .F.
  111. do while .T.
  112.      if mleft()
  113.           * button pressed, set flag
  114.           butdown = .T.
  115.      endif
  116.      if ! mleft() .and. butdown
  117.           * button released, check position
  118.           if mrow() >= 12 .and. mrow() <= 14 .and.;
  119.                mcol() >= 25 .and. mcol() <= 54
  120.                * mouse cursor in box
  121.                exit
  122.           else
  123.                * button release outside of box,
  124.                * reset button flag to start again
  125.                butdown = .F.
  126.           endif
  127.      endif
  128.      if inkey() = 13
  129.           * return key pressed
  130.           exit
  131.      endif
  132. enddo
  133. restore screen
  134. RETURN
  135.  
  136. The structure outlined above is basic to most programs that
  137. make use of the mouse, more complicated programs can offer a
  138. variety of actions depending upon the position of the mouse
  139. cursor and the button press/release sequence.
  140.  
  141. Once you have created functions that are mouse "aware", you
  142. can easily add support for other alternative input devices
  143. (including my personal favorite - the light pen, support for
  144. which can be found in "LIGHTPEN", available from the same
  145. friendly disks from where you plucked this) to your code.
  146.  
  147. A full demo of the mouse functions is included in this
  148. archive, entitled "MDEMO.PRG". Compile MDEMO and link it
  149. with RODENT (i.e. "link mdemo rodent,,,clipper") to try the
  150. mouse for yourself!
  151.  
  152. Enjoy!
  153. Lawrence Edward Nussbaum
  154. Contact via:   Compuserve     76137,361
  155.                The Source     BDW207
  156.                NYCENET
  157.  
  158.  
  159. References:
  160. Microsoft Mouse Programmers Reference Guide, 1986/1987,
  161. Microsoft Corporation, Redmond, Washington
  162.