home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / MOBUTTON.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.4 KB  |  118 lines

  1. /**
  2. *
  3. * Name        mobutton -- Report mouse button press/release history
  4. *
  5. * Synopsis    ercode = mobutton(event,pbuttons,pcount,pvert,phoriz);
  6. *
  7. *        int ercode      Error return code:
  8. *                    MO_OK if successful;
  9. *                    MO_ABSENT if mouse not found;
  10. *                    MO_BAD_OPT if event code not
  11. *                      recognized.
  12. *        int event      Button event to report, specified
  13. *                  by two bit fields:
  14. *
  15. *                    MO_LEFT, MO_RIGHT, or MO_MIDDLE;
  16. *                    MO_PRESS or MO_RELEASE.
  17. *
  18. *        unsigned *pbuttons
  19. *                  Returned status of buttons.  Any
  20. *                  of these bits may be set to
  21. *                  indicate that a button is pressed:
  22. *                    MO_LEFT
  23. *                    MO_RIGHT
  24. *                    MO_MIDDLE (bit always clear if
  25. *                      no third button exists).
  26. *        unsigned *pcount  Returned number of specified events
  27. *                    on specified button since the last
  28. *                    request.
  29. *        unsigned *pvert,*phoriz
  30. *                  Returned mouse position at the
  31. *                    time of the last specified event
  32. *                    on the specified button.
  33. *
  34. * Description    This function reports the number of presses or releases
  35. *        of a specified mouse button.  It also reports the mouse
  36. *        position at the time of the last specified event.  The
  37. *        counter for the specified event is then cleared.
  38. *
  39. *        The number of events reported reflects the number of
  40. *        occurrences since the last time the data was requested.
  41. *        The number of events is then cleared.  If another
  42. *        program queries the same item, the number reported will
  43. *        be smaller than the correct value, because the other
  44. *        program's query will erase the record of some of the
  45. *        occurrences.
  46. *
  47. *        The mouse position is reported in pixels relative to
  48. *        (0,0) at the upper left corner of the screen.
  49. *
  50. * Returns    ercode          Error return code:
  51. *                    MO_OK if successful;
  52. *                    MO_ABSENT if mouse not found;
  53. *                    MO_BAD_OPT if event code not
  54. *                      recognized or requested
  55. *                      button not present.
  56. *        b_mouse       Number of mouse buttons (0 if no driver).
  57. *        *pbuttons      Status of buttons.  Any
  58. *                  of these bits may be set to
  59. *                  indicate that a button is pressed:
  60. *                    MO_LEFT
  61. *                    MO_RIGHT
  62. *                    MO_MIDDLE
  63. *        *pcount       Number of specified events
  64. *                    on specified button since the last
  65. *                    request.
  66. *        *pvert,*phoriz      Mouse position at the
  67. *                    time of the last specified event
  68. *                    on the specified button.
  69. *
  70. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  71. *
  72. **/
  73.  
  74. #include <bmouse.h>
  75.  
  76. int mobutton(event,pbuttons,pcount,pvert,phoriz)
  77. int      event;
  78. unsigned *pbuttons,*pcount,*pvert,*phoriz;
  79. {
  80.     int    result;
  81.     DOSREG regs;
  82.  
  83.     if (moequip() <= 0)           /* Check mouse presence.          */
  84.     return MO_ABSENT;
  85.  
  86.                       /* Check mouse function number. */
  87.     switch (event & (MO_PRESS | MO_RELEASE))
  88.     {
  89.     case MO_PRESS:      regs.ax = 5;    break;
  90.     case MO_RELEASE:  regs.ax = 6;    break;
  91.     default:      return MO_BAD_OPT;
  92.     }
  93.  
  94.     switch (event & MO_ALLBUTTONS)
  95.     {
  96.     case MO_LEFT:     regs.bx = 0;  break;
  97.     case MO_RIGHT:     regs.bx = 1;  break;
  98.     case MO_MIDDLE:  regs.bx = 2;  break;
  99.  
  100.     default:     return MO_BAD_OPT;
  101.     }
  102.  
  103.     if (regs.bx > b_mouse)
  104.     return MO_BAD_OPT;          /* Requested button missing.    */
  105.  
  106.     result = mogate(®s,®s);
  107.  
  108.     if (result == MO_OK)
  109.     {
  110.     *pbuttons = regs.ax;
  111.     *pcount   = regs.bx;
  112.     *phoriz   = regs.cx;
  113.     *pvert      = regs.dx;
  114.     }
  115.  
  116.     return result;
  117. }
  118.