home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / s9302.zip / BRACHMAN.ZIP / SKEY.C < prev    next >
C/C++ Source or Header  |  1992-12-24  |  4KB  |  140 lines

  1. /*       S K E Y . C
  2.  
  3.     
  4.           ┌───────────────────────────────────┐
  5.           │     ▐███▌ ████     ▀██████  █████ │
  6.           │     █████▐████▌      ▀████  █████ │
  7.           │    █▐████▌█████        ▀██  █████ │
  8.           │   ▐█▌█████▐████▌     ▄█  ▀  █████ │
  9.           │   ███▐████▌█████    ███     █████ │
  10.           │  ▐███▌█████▐████▌    ▀█  ▄  █████ │
  11.           │  █████▐████▌█████      ▄██  █████ │
  12.           │ ▐█████▌█████▐████▌   ▄████  █████ │
  13.           │ ███████▐████▌█████ ▄██████  █████ │
  14.           ├───────────────────────────────────┤
  15.           │        Micro Endeavors, Inc.      │
  16.           │       3150 Township Line Road     │
  17.           │       Drexel Hill, PA   19026     │
  18.           └───────────────────────────────────┘
  19.   
  20.    demonstration 'C' library - adds the following:
  21.       skeyinit - arms keyboard for SEEK
  22.       skeykill - disables keyboard trap
  23.    author: Michael L. Brachman, Ph.D.
  24.    many thanks to George F. Goley, IV
  25. */
  26.  
  27. #include <dos.h>
  28. #include <pro_ext.h>
  29.  
  30. /* global variables */
  31. int       skeyid;
  32. Value     val;
  33. MHANDLE   mh;
  34. char     *cp;
  35. Point     pt;
  36. WHANDLE   wh;
  37.  
  38. /* function predefinitions */
  39. void dbback();
  40. void dbseek(char);
  41. FAR SKHandler(WHandle, EventRec FAR *);
  42.  
  43. /* initialization routine */
  44. void FAR skeyinit(ParamBlk FAR *parm)
  45. {
  46.   wh = _WOnTop();          /* get handle of window on top   */
  47.   mh = _AllocHand(100);    /* reserve some memory           */
  48.   _HLock(mh);              /* lock memory so it stays still */
  49.   val.ev_type = 'C';       /* define search string...       */
  50.   val.ev_length = 0;       /* ... as length 0 and ...       */
  51.   val.ev_handle = mh;      /* ... points to memory handle   */
  52.   cp = _HandToPtr(mh);     /* figure out real pointer too!  */
  53.   
  54.   /* now we attach our new event handler found below        */
  55.   skeyid = _ActivateHandler(SKHandler);
  56. }
  57.  
  58. /* removal routine, cleans up after itself */
  59. void FAR skeykill(ParamBlk FAR *parm)
  60. {
  61.   _HUnLock(mh);            /* unlock and ...                */
  62.   _FreeHand(mh);           /* ... free memory               */
  63.  
  64.   /* remove our event handler from consideration            */
  65.   _DeActivateHandler(skeyid);
  66. }
  67.  
  68. /* this is the actual event handler ...                     */
  69. /* ... it only looks at keyboard events for now             */
  70. FAR SKHandler(WHandle SWin, EventRec FAR *ev)
  71. {
  72.   /* a return value of YES tells FoxPro that we trapped ... */
  73.   /* ... event and to proceed with next event.  NO ...      */
  74.   /* ... tells FoxPro that it should handle the current ... */
  75.   /* ... event                                              */
  76.   int retval = NO; 
  77.   
  78.   if (ev->what == keyDownEvent) {
  79.     /* check to see if it is a legal character, upper case  */
  80.     if ( (ev->message >= ' ' && ev->message < 'a') ||
  81.          (ev->message >  'z' && ev->message <= 0x7E) ) {
  82.       dbseek(ev->message);
  83.       retval = YES;
  84.     }
  85.     else { /* check for lower case too! */
  86.       if (ev->message >= 'a' && ev->message <= 'z') {
  87.         dbseek(ev->message & 0xDF);  /* make upper case */
  88.         retval = YES;
  89.       }
  90.       else {  /* and check for backspace as well */
  91.         if (ev->message == '\b') {
  92.           dbback();
  93.           retval = YES;
  94.         }
  95.       }
  96.     }
  97.   }
  98.   return retval;
  99. }
  100.  
  101. /* this routine builds up a seek string by concatenating ...   */
  102. /* ... the character sent as an argument then doing a SEEK ... */
  103. /* ... then printing the character to the window on top        */
  104. void dbseek(char chr)
  105. {
  106.   val.ev_length += 1;
  107.   cp[val.ev_length-1] = chr;  /* add char to string */
  108.   _DBSeek(&val);
  109.   pt.h = val.ev_length;
  110.   pt.v = 0;
  111.   _WPosCursor(wh,pt);         /* position cursor in window */
  112.   _WPutChr(wh,chr);           /* print character in window */
  113. }
  114.  
  115. /* this routine erase 1 character if necessary and shortens  ... */
  116. /* ... the seek string and does a SEEK again                     */
  117. void dbback()
  118. {
  119.   if (val.ev_length > 0) {
  120.     pt.h = val.ev_length;
  121.     pt.v = 0;
  122.     _WPosCursor(wh,pt);
  123.     _WPutChr(wh,' ');  /* erase last character typed */
  124.     val.ev_length -= 1;
  125.     _DBSeek(&val);     /* seek against shorter string */
  126.   }
  127.   else  /* no characters left to trin, ring the bell  */
  128.     _PutChr(7);
  129. }
  130.  
  131. FoxInfo myFoxInfo[] = {
  132.     {"SKEYINIT", skeyinit, 0, ""},
  133.     {"SKEYKILL", skeykill, 0, ""},
  134. };
  135.  
  136.  
  137. FoxTable _FoxTable = {
  138.     (FoxTable FAR *)0, sizeof(myFoxInfo) / sizeof(FoxInfo), myFoxInfo
  139. };
  140.