home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / pcc / v08n03 / math.exe / ALGED21.ZIP / MOUSE.H < prev   
C/C++ Source or Header  |  1995-01-09  |  2KB  |  105 lines

  1. /*--------------------------------------------------------------------
  2.    This has similar mouse functions for DOS and OS/2
  3. */
  4. #ifdef __IBMC__
  5. /*--------------------------------------------------------------------
  6.    This is the code for OS/2
  7. */
  8. #define INCL_DOS
  9. #define INCL_SUB
  10. #include <os2.h>
  11.  
  12. HKBD hkbd = NULL;
  13. KBDKEYINFO kinfo;
  14. HMOU mousehandle;
  15.  
  16. int getch(void) {
  17.   int x;
  18.   if (!hkbd) KbdOpen(&hkbd);
  19.   KbdCharIn(&kinfo,1,hkbd);
  20.   return kinfo.chChar;
  21. }
  22.  
  23. int init_mouse(void) {
  24.   ULONG rc,act;
  25.   rc = MouOpen("MOUSE$",&mousehandle);
  26.   printf("\nmouopen rc %d\n",rc);
  27.   if (rc) return rc;                      
  28.   return -1;          /* -1 = success */
  29. }
  30. int show_mouse(void) { return 0; }
  31. int hide_mouse(void) { return 0; }
  32. int get_mouse(int *x,int *y) {
  33.   USHORT event,wait=1;
  34.   MOUEVENTINFO mloc;
  35.   MouReadEventQue(&mloc,&wait,mousehandle);
  36.   *x = mloc.col * 8;
  37.   *y = mloc.row * 8;
  38.   event = 0;
  39.   if (mloc.fs & 6) event |= 1;
  40.   if (mloc.fs & 24) event |= 2;
  41.   return event;
  42. }
  43.  
  44. #else
  45. /*--------------------------------------------------------------------
  46.    this is the code for DOS (Turbo C++)
  47. */
  48. #define MOUSEINT 0x33
  49. #include <dos.h>
  50.  
  51. /*
  52.    To do various functions (input) [output] set 'a' to
  53.     0 - test if loaded [reg.ax = $ffff]
  54.     1 - show cursor
  55.     2 - hide cursor
  56.     3 - get position [b buttons, c x, d y]
  57.     4 - set position (c x,d y)
  58.     5 - press button   (b buttons, c x, d y) [b count]
  59.     6 - release button (b buttons, c x, d y) [b count]
  60.     7 - set x range  (c min, d max)
  61.     8 - set y range  (c min, d max)
  62.     10- text cursor  (b 0=soft 1=hard, c ?, d ?)
  63.     15- mickeys      (c xscale, d yscale?)
  64. */
  65. int mouse(int a,int *b,int *c,int *d)
  66. {
  67.   static union REGS regs;
  68.   regs.x.ax = a;
  69.   regs.x.bx = *b;
  70.   regs.x.cx = *c;
  71.   regs.x.dx = *d;
  72.   int86(MOUSEINT,®s,®s);
  73.   *b = regs.x.bx;
  74.   *c = regs.x.cx;
  75.   *d = regs.x.dx;
  76.   return regs.x.ax;
  77. }
  78.  
  79. int init_mouse(void) {
  80.   int x=0;
  81.   long *p;
  82.   /*  this is some code to try to avoid hangs when int 33 is not
  83.       loaded with anything. */
  84.   p = (long*)(MOUSEINT * 4);
  85.   if (*p==0) return 1;
  86.   return mouse(0,&x,&x,&x);
  87. }
  88.  
  89. int show_mouse(void) {
  90.   int b=0; return mouse(1,&b,&b,&b);
  91. }
  92.  
  93. int hide_mouse(void) {
  94.   int b=0; return mouse(2,&b,&b,&b);
  95. }
  96.  
  97. int get_mouse(int *x,int *y) {
  98.   int b=0; mouse(3,&b,x,y); return b;
  99. }
  100.  
  101. int set_mouse(int x,int y) {
  102.   int b=0; return mouse(4,&b,&x,&y);
  103. }
  104. #endif
  105.