home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / CENVIW9.ZIP / BUGHUNT.CMM < prev    next >
Text File  |  1994-03-08  |  3KB  |  74 lines

  1. /*************************************************************************
  2.  *** BugHunt.cmm - Example program for using the ClipBoard routines in ***
  3.  *** ver.1         ClipBrd.lib.  This is a very silly program that     ***
  4.  ***               searches every few seconds for the text of "bug"    ***
  5.  ***               anywhere in the clipboard text.                     ***
  6.  ***                                                                   ***
  7.  ***               This program also demonstrates the unusual          ***
  8.  ***               technique of calling CEnvi to execute code contain  ***
  9.  ***               within the source of another CEnvi program.         ***
  10.  *************************************************************************/
  11.  
  12. #define  BUGHUNT_FREQUENCY    5   // how many seconds to wait between hunts
  13.  
  14. #include <ClipBrd.lib>
  15. #include <MsgBox.lib>
  16.  
  17.  
  18. MessageBox("This program will search for\n"
  19.            "bugs in your clipboard. That\n"
  20.            "is, it will search for the\n"
  21.            "word \"bug\" (case-insensitive)\n"
  22.            "and ask you if you want to\n"
  23.            "delete the clipboard if a\n"
  24.            "\"bug\" is found.",
  25.            "EXTERMINATOR!");
  26.  
  27.  
  28. for(;;) {   // FOREVER
  29.    ClipText = GetClipboardData(CF_TEXT);
  30.    if ( ClipText != NULL ) {
  31.       // check clipboard, case-insensitive, for the "bug" string
  32.       while ( NULL != (ClipText = strpbrk(ClipText,"Bb")) ) {
  33.          // check if the rest of this is "ug"
  34.          if ( !memicmp(++ClipText,"ug",2) ) {
  35.             if ( ExterminationWanted() )
  36.                ExterminateTheClipboard();
  37.             break;
  38.          }
  39.       }
  40.    }
  41.    suspend(BUGHUNT_FREQUENCY * 1000);
  42. }
  43.  
  44. ExterminationWanted() // Return TRUE if user wants to delete the clipboard
  45. {
  46.    return ( IDYES == MessageBox("A bug has been found in\n"
  47.                                 "the clipboard. Should the\n"
  48.                                 "clipboard be exterminated?",
  49.                                 "EXTERMINATOR!",
  50.                                 MB_YESNO) );
  51. }
  52.  
  53. ExterminateTheClipboard() // spawn message program to run while this program
  54. {                         // deletes the text in the clipboard.
  55.    // Run another CEnvi process to tell that extermination is happening.
  56.    // That other program will read the code from this program; weird, huh!
  57.    spawn(P_NOWAIT,"CEnvi #include <BugHunt.cmm,,//Exterminator!> ");
  58.    // while that's going on, we'll simultaneously delete the clipboard
  59.    PutClipboardData(NULL);
  60. }
  61.  
  62.  
  63. // The text below, which is a comment in this program, is the CODE for another
  64. // instance of CEnvi which was spawned above in the ExterminateTheClipboard()
  65. // routine.  Since Windows is multitasking (sort of) this code will be running
  66. // while the original instance of CEnvi is deleting the clipboard.
  67.  
  68. //Exterminator!   for ( i = 0; i < 100; i++ ) {
  69. //Exterminator!      printf("Bug!\tEEEK!\t");
  70. //Exterminator!   }
  71. //Exterminator!   suspend(500);
  72. //Exterminator!   printf("\nCLIPBOARD EXTERMINATED!");
  73. //Exterminator!   suspend(500);
  74.