home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / cenvi29.zip / BOUNCY.CMD < prev    next >
OS/2 REXX Batch file  |  1994-03-08  |  4KB  |  132 lines

  1. EXTPROC CEnvi
  2. /**************************************************************
  3.  *** Bouncy.cmd - Start a bouncy OS/2 Command Window. This  ***
  4.  *** ver.1        demonstrates moving windows, embedding    ***
  5.  ***              multiple Cmm executables within one file, ***
  6.  ***              passing keystrokes, clipboard use, and    ***
  7.  ***              silliness.                                ***
  8.  **************************************************************/
  9.  
  10. #include <PMdll.lib>
  11.  
  12. // Spawn a copy of the command processor, so that all looks normal
  13. CmdChildID = spawn(P_NOWAIT,defined(OS2_SHELL) ? OS2_SHELL : "CMD.EXE" );
  14.  
  15. ForeverBounce(CmdChildID);
  16.  
  17.  
  18. #define  DELAY_BETWEEN_MOVEMENTS   100 // in milliseconds
  19. #define  COL_AVERAGE_MOVE  4           // average column movement
  20. #define  ROW_AVERAGE_MOVE  4           // average row movement
  21. #define  COL_RANDOM_DELTA  2           // allowed change from average move to
  22. #define  ROW_RANDOM_DELTA  2           // randomize the bounces
  23.  
  24.  
  25. ForeverBounce(ChildProcessID)   // bounce forever and ever while CMD runs
  26. {
  27.    // // INCREASE PRIORITY OF THIS PROCESS
  28.    // #define ORD_DOS32SETPRIORITY     236
  29.    // #define PRTYC_TIMECRITICAL 3     // very high priority
  30.    // DynamicLink("doscalls",ORD_DOS32SETPRIORITY,BIT32,CDECL,
  31.    //             0/*all threads*/,PRTYC_TIMECRITICAL/*idletime*/,
  32.    //             0/*no process change at new level*/,0/*current process*/)
  33.  
  34.    // Get the dimensions of the desktop
  35.    #define HWND_DESKTOP 1
  36.    GetWindowPosition(HWND_DESKTOP,Col,Row,DeskWidth,DeskHeight);
  37.  
  38.    // Get initial position of the Bouncy Window
  39.    GetWindowPosition(Info().WinHandle,Col,Row,Width,Height);
  40.  
  41.    // determine maximum and minimum values for Col and Row
  42.    MinCol = 0;
  43.    MinRow = 0;
  44.    MaxCol = DeskWidth - Width;
  45.    MaxRow = DeskHeight - Height;
  46.  
  47.    // start random direction and delta
  48.    srand();
  49.    ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,rand() & 1);
  50.    RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,rand() & 1);
  51.  
  52.    // Finally, keep bouncing the window around at every interval
  53.    while ( ValidProcessID(ChildProcessID) ) {
  54.  
  55.       // move window to new Row and Col position
  56.       MoveWindow(Info().WinHandle,Col += ColSpeed,Row += RowSpeed);
  57.  
  58.       // check if needs to bounce back to to hitting desktop edge
  59.       if ( ColSpeed < 0 ) {
  60.          if ( Col < MinCol )
  61.             BouncyBeep(),
  62.             ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,TRUE);
  63.       } else {
  64.          if ( MaxCol < Col )
  65.             BouncyBeep(),
  66.             ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,FALSE);
  67.       }
  68.       if ( RowSpeed < 0 ) {
  69.          if ( Row < MinRow )
  70.             BouncyBeep(),
  71.             RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,TRUE);
  72.       } else {
  73.          if ( MaxRow < Row )
  74.             BouncyBeep(),
  75.             RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,FALSE);
  76.       }
  77.  
  78.       suspend(DELAY_BETWEEN_MOVEMENTS);
  79.    }
  80. }
  81.  
  82. GetRandomSpeed(average,deviation,positive) // if not positive then negative
  83. {
  84.    // get a random deviation from average
  85.    deviate = (rand() % (2*deviation + 1)) - deviation;
  86.  
  87.    if ( positive )
  88.       return( average + deviate );
  89.    else
  90.       return( -average - deviate );
  91. }
  92.  
  93. GetWindowPosition(hwnd,Col,Row,Width,Height)
  94. {
  95.    #define SWP_BLOB_SIZE 9 * 4
  96.    BLObSize(swp,SWP_BLOB_SIZE);
  97.    #define ORD_WIN32QUERYWINDOWPOS  837
  98.    if !DynamicLink("PMWIN",ORD_WIN32QUERYWINDOWPOS,BIT32,CDECL,hwnd,swp)
  99.       exit(1);
  100.    Height = BLObGet(swp,4,SWORD32);
  101.    Width = BLObGet(swp,8,SWORD32);
  102.    Row = BLObGet(swp,12,SWORD32);
  103.    Col = BLObGet(swp,16,SWORD32);
  104. }
  105.  
  106. MoveWindow(hwnd,col,row)
  107. {
  108.    #define ORD_WIN32SETWINDOWPOS 875
  109.    #define SWP_MOVE              0x0002
  110.    #define SWP_NOADJUST          0x0040
  111.    PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWPOS,BIT32,CDECL,
  112.                  hwnd,0,col,row,0,0,SWP_MOVE | SWP_NOADJUST);
  113. }
  114.  
  115. ValidProcessID(id)   // return TRUE if this ID is OK
  116. {
  117.    if ( pList = ProcessList(False) ) {
  118.       for ( li = GetArraySpan(pList); 0 <= li; li-- ) {
  119.          if ( id == pList[li].id )
  120.             return(True);
  121.       }
  122.    }
  123.    return False;
  124. }
  125.  
  126. BouncyBeep()
  127. {
  128.    #define ORD_DOS32BEEP   286
  129.    DynamicLink("doscalls",ORD_DOS32BEEP,BIT32,CDECL,400,5)
  130. }
  131.  
  132.